0
\$\begingroup\$

I'm using vector3 as direction of object movement and i want to smoothly rotate it to another direction vector. I found SLERP but it rotate by percent. Looks like Vector3.RotateTowards is what i need, but i can't find the source code of this method and my project is not on Unity.

So, can you help me realize rotation like SLERP but by fixed angle? Thanks

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Here's an example implementation:

Vector3 fromDirection = fromVector.normalized;
Vector3 toDirection = toVector.normalized;

float angleRadians = Mathf.Acos(Vector3.Dot(fromDirection, toDirection));

float angleDegrees = Mathf.Min(angleRadians * Mathf.Rad2Deg, maxAngleDegrees);

Vector3 axis = Vector3.Cross(fromDirection, toDirection);

Quaternion rotationIncrement = Quaternion.AngleAxis(angleDegrees, axis);

outputVector = rotationIncrement * fromVector;
\$\endgroup\$
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .