SA-MP Forums Archive
Yrot calculation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Yrot calculation (/showthread.php?tid=291191)



Yrot calculation - wups - 18.10.2011

I've spent the whole evening trying to figure it out, but just can't come up with a formula. Could anyone help me, when Coordinates of two objects are known, X1rot and Z1rot are also known.

NEED: Y1Rot(to face object2)


Re: Yrot calculation - Drebin - 18.10.2011

So what do you want ? Y Rotation of an object ?
GetObjectRot();


Re: Yrot calculation - wups - 18.10.2011

Quote:
Originally Posted by Drebin
Посмотреть сообщение
So what do you want ? Y Rotation of an object ?
GetObjectRot();
I want to calculate the Yrotation for an object facing another object.


Re: Yrot calculation - Drebin - 18.10.2011

Not possible I believe
Because the Y rotation can have ANY value independent from the X and Z rotation or the coordinated of the other object (Z axis needed here anyway)


Re: Yrot calculation - wups - 18.10.2011

If you want it FACING another object, than it can't have any value, it does depend from x and z axis.


Re: Yrot calculation - Kyle - 19.10.2011

It's the Z angle which needs working out, you need to work it out with some special formular which gets tangent, sin thing shit. Didn't really understand it, after hours of indentating + coding + testing. ********* and Me got there in the end.


Re: Yrot calculation - wups - 19.10.2011

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
It's the Z angle which needs working out, you need to work it out with some special formular which gets tangent, sin thing shit. Didn't really understand it, after hours of indentating + coding + testing. ********* and Me got there in the end.
Same story here, but Z finding was MUCH easier.

I've changed the Y axis to Z, so that it makes things clear.
Yes, I can't find any info about calculating.
This worked out for Z:
pawn Код:
Angle[0] = clampex(270.0 - atan2( Coo[3]-Coo[0],Coo[4]-Coo[1]));
i guess you understand what clampex does.
And i tried the same for Y:
pawn Код:
Angle[4]=clampex(90.0 - atan2( Coo[3]-Coo[0],Coo[5]-Coo[2]));
Well that didn't work out the same as Z.
Coo[0] and Coo[3] is X,
Coo[1] and Coo[4] is Y,
Coo[2] and Coo[5] is Z.

If you're wondering why im i substracting atan from 90, it's because its the zero rotation value.


Re: Yrot calculation - RyDeR` - 19.10.2011

Search for Euler Angles. It should give you enough information to create this "function".


Re: Yrot calculation - wups - 19.10.2011

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Search for Euler Angles. It should give you enough information to create this "function".
I did and to be honest, i didn't find anything usefull for this. And I don't want to read everything :S

EDIT:
Thanks for the help guys, this did the trick:
pawn Код:
Angle[4]=(92.5-(atan2( Coo[3]/Coo[0],Coo[5]-Coo[2])-120.0)/2);



Re: Yrot calculation - Kyle - 19.10.2011

Quote:
Originally Posted by wups
Посмотреть сообщение
I did and to be honest, i didn't find anything usefull for this. And I don't want to read everything :S

EDIT:
Thanks for the help guys, this did the trick:
pawn Код:
Angle[4]=(92.5-(atan2( Coo[3]/Coo[0],Coo[5]-Coo[2])-120.0)/2);
Can you show us a picture of your final thing please? Unsure what it was suppose to look like.

#Kyle