Xwad Posted February 24, 2019 Share Posted February 24, 2019 (edited) Well it is a difficult problem for me and i can't explain it well. Hope you understand my problem. I want to rotate a vehicles Z axis to the closer direction of the target Z. For example: if the vehicles Z is 90˙ and target Z is 180˙ then rotate it in the positive direction (z=z+1) . If the target Z is 20˙ then rotate it in the negativ direction (z=z-1). always in the direction which is closer. Edited February 24, 2019 by Xwad Link to comment
Moderators IIYAMA Posted February 24, 2019 Moderators Share Posted February 24, 2019 @Xwad function getRotationOffset (rot1, rot2) local rotationOffset = (rot1 - rot2 + 360) % 360; if (rotationOffset > 180) then rotationOffset = 360 - rotationOffset else rotationOffset = -rotationOffset end return rotationOffset end function getRotationDifference (rot1, rot2) local rotationDifference = (rot1 - rot2 + 360) % 360; if (rotationDifference > 180) then rotationDifference = 360 - rotationDifference end return rotationDifference end Test them out and see which one you think need. getRotationOffset positive and negative. getRotationDifference only positive. Link to comment
Xwad Posted February 24, 2019 Author Share Posted February 24, 2019 yeeees, that's what i needed, thanks a lot 1 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