- Home /
Question by
Bernie-Buddy · Jun 14, 2021 at 06:26 PM ·
rotationvector3matrix
How do I apply a rotation to a vector3?
Simply put, what is the more efficient way of writing something akin to this:
public GameObject view;
public Vector3 modelOffset;
transform.localPosition = view.transform.right * modelOffset.x + view.transform.up * modelOffset.y + view.transform.forward * modelOffset.z;
Comment
Answer by Bunny83 · Jun 14, 2021 at 06:35 PM
You rotate a vector by using the rotation quaternion and multiply the vector with the quaternion on the left. So it should be
transform.localPosition = view.transform.rotation * modelOffset;
Your answer
Follow this Question
Related Questions
Change the roll of the rotation 0 Answers
Quaternion.Euler rotations don't add up 0 Answers
How can I replace this Vector3 with a float? 2 Answers
Which direction to rotate a vector for desired velocity? 0 Answers