Wisin Posted October 18, 2010 Share Posted October 18, 2010 hi, i made a track script that allows the player to track another player and a label will appear at screen with the meters he is from you, all working fine but i want to make like "Robot is approximately 50 north from you" my question is, how i make that "north" or "south"? thanks in advance. Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 you need all directions (W E N S) or just N S ? if Y of "robot" > Y of player - north, else - south. Link to comment
Wisin Posted October 18, 2010 Author Share Posted October 18, 2010 thats my question, can you give me a little example of what i need to make? Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 i asked you if you need only N/S or all directions?... you didnt answer Link to comment
Wisin Posted October 18, 2010 Author Share Posted October 18, 2010 oh sorry i didn't readed it all, all directions. Link to comment
dzek (varez) Posted October 18, 2010 Share Posted October 18, 2010 you need to get distance 2d between player and robot, "virtually create" point C placed your distance length to north ( so X of player, Y + distance), count the angle PLAYER, C, ROBOT (trigonometry, search wikipedia), now if robot X < player X - add 180 to result. you will get direction (azimuth). now if its: 0-45 or 315-360 == north 45-135 == east 135-225 = south 225 - 315 = west edit: function to count angle between 3 points: function getAngleBetweenPoints2D(ax,ay,bx,by,cx,cy) local AB = { ax-bx, ay-by } local BC = { cx-bx, cy-by } local AB_ = getDistanceBetweenPoints2D(ax,ay,bx,by) local BC_ = getDistanceBetweenPoints2D(bx,by,cx,cy) local iloczynSkalarny = AB[1]*BC[1] + AB[2]*BC[2] local tmp = iloczynSkalarny/(AB_*BC_) local kat = math.acos(tmp) local degrees = kat*180/(22/7) --outputChatBox("deg "..degrees) return degrees end -- note: in my script there was angle invertion on return (180-degrees) - not sure if you should use it or not, as i dont remember it exactly Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 i made this but keeps returning "north" and "east" x, y, z = getElementPosition ( ped ) x2, y2, z2 = getElementPosition ( player ) distance = getDistanceBetweenPoints2D ( x, y, x2, y2 ) local newvalue = math.floor ( distance ) local loc = getAngleBetweenPoints2D(x,y,x2,y2,x,y2) if loc < 45 then loca = "north" elseif loc < 135 then loca = "east" elseif loc < 225 then loca = "south" elseif loc < 315 then loca = "west" Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 you didnt read carefully.. try this one, should work, but im not a math god, also this was written in browser.. local px,py,pz = getElementPosition(player) local rx, ry, rz = getElementPosition(bot) local distanceBetweenPlayerAndBot = getDistanceBetweenElements2D(px,py,rx,ry) local cx = px local cy = py+distanceBetweenPlayerAndBot local angle = getAngleBetweenPoints2D(px,py,cx,cy,rx,ry) if rxif (angle >= 0 and angle < 45) or (angle > 315 and angle <= 360) then direction = "north" elseif (angle>45 and angle <= 135) then direction = "east" elseif (angle>135 and angle <= 225) then direction = "south" elseif (angle>225 and angle <= 315) then direction = "west" end Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 dosn't works makes this error: attempt to call global 'getDistanceBetweenElements2D' (a nil value), at line: local distanceBetweenPlayerAndBot = getDistanceBetweenElements2D(px,py,rx,ry) Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 maybe try doing something by yourself? i told you it was written in browser - the only thing you had to do is open wiki and see my mistake. it's: getDistanceBetweenPoints2D ... Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 thank you, its working Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 are directions ok? or just script is not broking? im wondering if i did everything right as i suck at maths Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 i walk around the bot and it sets to south,west,north etc Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 are the directions correct? not inverted or just random? Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 lets hope they are correct, i don't know how to test that. Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 lol, just go to the north from the bot and check if it is saying "south"? same for other directions.. Link to comment
Wisin Posted October 21, 2010 Author Share Posted October 21, 2010 yes directions are correct i checked and they're right thanks again. Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 your welcome, im happy that math thing done by me actually worked Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now