Moderators Lord Henry Posted July 22, 2017 Moderators 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? Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
Mr.Loki Posted July 23, 2017 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 [REL]Cinema Experience Beta 2.0 [TUT]Object offsets with OOP. [TUT] Adding a Discord bot to your server. Discord: Loki#7355
Moderators Lord Henry Posted July 23, 2017 Author Moderators 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 Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
Moderators Lord Henry Posted July 24, 2017 Author Moderators Posted July 24, 2017 UP Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
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