Jump to content

How to find a X angle between 2 points


Recommended Posts

  • Other Languages Moderators
9 hours ago, Mr.Loki said:

Another way of calculating the angles.


x = ( 360 - math.deg(math.atan2((target.y - object.y), (target.z - object.z))) ) % 360
y = ( 360 - math.deg(math.atan2((target.x - object.x), (target.z - object.z))) ) % 360

 

Not working...
I am using this:

function findRotationZ (x1, y1, x2, y2) --This is working fine.
    local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
    return t < 0 and t + 360 or t
end

function findRotationX (y1, z1, y2, z2)
    local r = ( 360 - math.deg(math.atan2((y1 - y2), (z1 - z2))) ) % 360
    return r < 0 and r + 360 or r
end

addCommandHandler ("tar", function ()
    local x,y,z 	= getElementPosition(localPlayer) -- I am the target
    local tx,ty,tz 	= getElementPosition(topLightA51a) -- the object that will face me.
    setElementRotation (topLightA51a, findRotationX(y,z,ty,tz), 0, findRotationZ(x,y,tx,ty)-180 ) --Make the object face me, actually only Z axis is correct.
end)

(It's a Client-sided script)

Edited by Lord Henry
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...