Jump to content

track player


Wisin

Recommended Posts

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...