How to rotate a vector towards another vector in a smooth easing manner not Instantly?

If you are working in 2D, I would highly suggest looking at the LookAt demo from the Godot 2.1 demo repository. You'll probably need to update/refactor the code to make it work for Godot 3, but it should hopefully give an idea on how to rotate smoothly between two points.

If you are using 3D, I'm not 100% sure on how to go about it. I know I've done this before for 3D, but I do not remember how I achieved it.

I'm new to Godot so I don't really know of an engine-specific way of doing it. However, mathematically it isn't too bad if you know how vectors work.

1) Taking the cross-product between your current vector (vector A) and the desired vector (vector B ) will result in the vector you need to rotate around (vector C) to get from one to the other. You would want to normalize this resulting vector.

2) In order to rotate vector A around vector C some value of degrees / radians you can take a look at the formula explained here.

3) To get the "smooth" portion you will want to rotate a fraction of the total number of degrees / radians between vector A and B. You can get the number of total radians between the vectors by taking the dot-product of the normalized versions of A and B to give you the scalar S. Then take the arccos of S to give the total number of radians.

This should give you all the data you need to figure out how to rotate vector A and how much it needs to be rotated to make a smooth transition over some period of time.

E.g., you could have a script that calculates vector C and (theta) the number of radians between vector A and B at the start. Then, assuming you want it to transform fully over the period of a second you could call the rotation script repeatedly on vector A while providing the number of radians to rotate as theta * delta.

EDIT: Well, should have done this from the start. Oops.

Looking at the docs it looks like the Vector3 class has the functions angle_to and rotated which performs step 3 and step 2, respectively. This should make the task much simpler on your part.

4 years later