How To Rotate A Vector Toward Another Vector While Keeping The Same Magnitude

I am a bit fuzzy on vector math. How would I do the following:

A = Vector3 (with a certain magnitude)
B = Vector3 (unit vector with the direction I want to point in)

How do I get a Vector3 with the magnitude of A but in the direction of B?

1 Like

I believe you’d just do B * A.

Not too experienced with Vector math so I could be wrong.

1 Like

Assuming these are vectors, not points…

-- Assuming B is a unit vector...

C = B*A.Magnitude
-- If B is any vector...

C = B.Unit*A.Magnitude

In other words, you take the vector with a length of 1 and multiply it by the length you want it to be.

7 Likes

Just to break it down a bit more, we can look at it like this:

We want the resulting Vector3 to be the length of Vector A. We can get this number using “A.Magnitude”
We get the direction of Vector B by doing “B.Unit”. This gives us a unit vector, meaning it has a length of 1.

Thus, we can get Vector C as follows:
C = A.Magnitude * B.Unit

Edit: Corecii beat me to it

4 Likes