Other Languages Moderators Lord Henry Posted July 22, 2017 Other Languages Moderators Share Posted July 22, 2017 Hello everyone. I am trying to make an object look at me. It's partially working, I make the object rotate the Z axis to face me (using this: FindRotation), but I need to rotate the X axis too. How can I do it? Link to comment
Mr.Loki Posted July 23, 2017 Share Posted July 23, 2017 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 Link to comment
Other Languages Moderators Lord Henry Posted July 23, 2017 Author Other Languages Moderators Share Posted July 23, 2017 (edited) 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 July 23, 2017 by Lord Henry Link to comment
Other Languages Moderators Lord Henry Posted July 24, 2017 Author Other Languages Moderators Share Posted July 24, 2017 UP 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