- Home /
Controlling the speed of Vector3.RotateTowards
I was originally using a Vector.Slerp to rotate an object to a certain angle, however I didn't want any easing in the rotation. Therefore I changed my code to use Vector3.RotateTowards instead which solved the easing issue. My code now looks like this:
Start
originalRotation = door.eulerAngles;
openRotation = new Vector3 (originalRotation.x, originalRotation.y + doorAngle, originalRotation.z);
Update
door.eulerAngles = Vector3.RotateTowards(door.eulerAngles, openRotation, doorSpeed * Time.deltaTime, 0.1f);
The issue now is that no matter what "doorSpeed" (maxRadiansDelta) is changed to, the rotation speed of the object does not change. However, changing the maxMagnitudeDelta (0.1f above) does change the speed. I am confused as to what the difference is between maxRadiansDelta and maxMagnitudeDelta, and more specifically which of the two should be used to control the rotation speed. In the Unity Documentation example the maxRadiansDelta is made to equal speed * Time.deltaTime so I assumed that this controlled the speed, but that doesn't seem to be the case for my code.
Could someone please explain to me how this works? I have used Quaternion.RotateTowards previously, however for this situation, since I am using specific angles I feel that it is much easier to work with vectors than quaternions.
V3.Slerp has easing? Are you sure? The docs says it's linear (so no easing.)
$$anonymous$$ost likely the easing is caused by using the result of the previous lerp as a value for the current lerp.
The illustration on this page kind of describes what's happening.
Don't use result of previous lerp in another lerp. Don't use deltaTime as argument for lerp. It just means you don't know what you are doing.
Your answer
Follow this Question
Related Questions
Rotate slowly to target position? 3 Answers
Vector 3. Slerp 1 Answer
How to make top-down objects rotate to face another? 1 Answer
Rotate Towards doesnt work as expected 2 Answers
Vector3 precision issue? 2 Answers