- Home /
http://answers.unity3d.com/questions/502295/how-can-i-rotate-an-object-180-degrees-c.html
How can you make a nav mesh agent rotate 180 degrees?
I have a capsule nav mesh agent (c is the agent in the code) that I'm trying to rotate 180 degrees after it stops moving completely. I think I may be using the wrong c.transform.rotation values in the code as they Debug.Log somewhere close to 0 and I think you are not suppose to modify Quaternion values either. If so how can I make the nav mesh agent turn 180 degrees? Thanks!
Quaternion LocalR1 = new Quaternion (0, c.transform.rotation.y, 0, c.transform.rotation.w);
Quaternion LocalR2 = new Quaternion (0, c.transform.rotation.y + 180f, 0, c.transform.rotation.w);
c.transform.rotation = Quaternion.Slerp (LocalR1, LocalR2, Time.deltaTime * 10);
Answer by IgnoranceIsBliss · Jun 17, 2017 at 10:00 PM
Time.deltaTime is the time taken to render this one frame. It doesn't increase over time. The last parameter to 'Slerp' isn't going to go much higher than 0.05.
You should store your own time offset (ie. the time you started turning around) and subtract this from Time.time. That will give you the correct value to pass to Slerp.