- Home /
When Vector3.RotateTowards is given a negative speed value (maxRadiansDelta), it points to the opposite direction but does so with a stutter? How can I remove that stutter?
With Vector3.RotateTowards, the document on it says, "If a negative value is used for maxRadiansDelta (which is basically the speed value), the vector will rotate away from target/ until it is pointing in exactly the opposite direction, then stop."
(from: http://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html)
And so I decided to test this out on a simple cube with the following code:
var newDir : Vector3;
function Update ()
{
var dirFwd = Vector3(0,0,1);
Debug.DrawRay(transform.position, dirFwd, Color.blue);
var dirRight = Vector3(1,0,0);
Debug.DrawRay(transform.position, dirRight, Color.red);
if (Input.GetKey("w"))
{
newDir = Vector3.RotateTowards(transform.forward, dirFwd, 0.1, 0);
}
if (Input.GetKey("d"))
{
newDir = Vector3.RotateTowards(transform.forward, dirRight, -0.1, 0);
}
transform.rotation = Quaternion.LookRotation(newDir);
However, when you do press down d, while the cube does rotate to the opposite direction, it stutters once it reaches the target direction.
Does anyone know why it is doing this?
I tried to use: newDir = Vector3.RotateTowards(-transform.forward, dirRight, 0.1, 0);
but it still stutters... I guess I can try to just avoid using this function, but I'm really curious about whether if I'm doing something wrong or if there is something glitchy about this particular function :(