How to rotate vector based on another reference vector?

I have the red vector A which is the vector I want to rotate,

and the reference black vector R. which is the reference I want to use for the rotation

I want to give a new value for black vector R and make sure that A is correctly rotated to match the new R

This happens on the XZ axis

The expected workflow is that for example I start with A(-8,0,0), R(0,0,-1)
I manually change R to (1,0,0)
And I am expecting an new output for A of (0,0,-8)

How can I achieve this?

Any help is appreciated ,thanks!

Get the rotation between the two directions, then rotate both vectors by that rotation.

Basically use Quaternion.FromToRotation followed by the Quaternion * Vector3 operator.

1 Like

For math-heavy problems, ask ChatGPT to generate code for you, it’s correct 90% of cases.