7

I've seen quite a lot of questions like this, and the trouble is - the question makes no sense. They are not the same thing, it is a bit like saying "how do I convert an apple into a brick"?

But usually the underlying question does make sense, it is the wording that is suspect.

What I want to do is this:

  • I have an object in the world space frame of reference with a rotation represented by the Quaternion R.
  • if that object were to move forwards relative to its local frame of reference, ie straight along its local Z axis, by a nominal amount ...
  • ... what would be the Vector3 whose (normalised) components represent that movement in the world frame of reference?

Now, I think the answer is

    Vector3 ans = R * Vector3.forward;

Is this right, and if so, why? (If not right, then what is the answer?)

3
  • That is right - are you asking how unity calculates the result? That seems like more of a math question. Commented Jul 12, 2020 at 6:13
  • No, not really. I am just trying to get my head around qualitatively why that calculation produces that result. Commented Jul 12, 2020 at 6:39
  • 1
    What are you trying to ask? When you multiply Quaternion with Vector you rotate the Vector on rotation which contains in quaternion. Or you need another information? Commented Jul 12, 2020 at 12:37

1 Answer 1

11

Yes that is correct.

Quaternion * Vector3 takes a given vector and rotates it according to the given rotation.

So if your R is basically the object's world-space transform.rotation then the result will be the objects local forward (positive Z) vector as a vector in world space coordinates.


You can also directly use the object's transform.forward vector which basically equals transform.rotation * Vector3.forward

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.