So basically, is there a way to specify whether you’d like to rotate something clockwise or anti-clockwise?
Say if you’re using a Mathf.SmoothDampAngle or Slerp etc. to rotate an object!
So basically, is there a way to specify whether you’d like to rotate something clockwise or anti-clockwise?
Say if you’re using a Mathf.SmoothDampAngle or Slerp etc. to rotate an object!
Are you talking about the shortest angle between two angles?
Mathf.DeltaAngle
Thanks for answering! In my case, the distance between both angles is 180 degrees!
This is the type of problem I have -
(At the moment the character rotates clockwise by default)
Ideally, I’d like to be able to specify which direction the character will rotate!
Ok, I just figured out a solution to my problem!
If anyone’s interested or has a similar problem, I solved it by creating a bit a script that changed the character’s rotation by a single degree when it was running upward…this way the distance in degrees to rotate anti-clockwise to the target was 179 degrees…and clockwise was then 181 degrees to target.
By default Unity will always rotate objects to their target by the acutest angle (179 in my case forcing an anti-clockwise rotation), otherwise if the distance is 180 degrees Unity will default to a clockwise rotation.
my unity is not rotating to the nearest angle. i have an object using another object’s rotation to set its own using a MoveToward (i need it to be not instantaneous) and instead of turning 90 degrees counterclockwise, it is choosing to rotate 270 degrees clockwise. when i was using another method it turned the correct direction but then continued to turn. the target object says “-90”, not “270” so that’s not the issue
First, it’s bad manners to reply to a post that’s over 10 years old. It would probably help if you started your own thread, explaining everything from the beginning, instead of trying to explain things relative to a conversation that ended so long ago.
Second, MoveToward has nothing to do with rotation. But RotateToward will follow the rule stated above. If you’re at 38º and you rotate toward -90º, it finds CCW (-128º total) to be closer than CW (+232º). When in doubt, Vector3.SignedAngle() might help you keep angle numbers in the [-180, +180] range so you can see them, but the math APIs don’t care, and will treat -90 and +270 as the same.
didn’t know about the manners, sorry. i also used RotateToward which did the exact same thing. thank you. i will try SignedAngle.
Don’t worry, everybody has to start somewhere. Though those are some general forum rules that usually apply to any internet forum.
The scripting forum specifically has this sticky post at the very top which explains the “Code of Conduct”.