- Home /
How would I rotate a position vector to get a new position vector.
I have a position vector3 that I want to rotate in worldspace, then return the new position vector3.
Let's say it's 100,0,0. If I rotate it 180 degrees it may be -100,0,0. Is there a function for that?
I looked through the docs but couldn't find one that takes a vector and a rotation and returns a vector.
Thanks, Dan
Answer by Bunny83 · Sep 20, 2011 at 04:08 AM
You can multiply a Quaternion with a Vector3. Are you sure you've even searched for that, because the Quaternion doesn't have much methods or operators so it's hard to belive you've missed it.
btw:
To "convert" a Vector3 into a rotation(Quaternion) you can use Quaternion.LookRotation. To get a Vector3 from a rotation just multiply the quaternion with Vector3.forward.
I didn't see the second method just the first...Also I tried it earlier and got an error so I figured it couldn't be done. But... I tried vec*quat which gave an error. quat * vec worked.
myvec=Vector3(0,0,10);
myquat=GameObject.Find("go").transform.rotation; //go is rotated 180 around y axis.
newvec=myquat*myvec;
Debug.Log(newvec);
//output = (0,0,-10);
Your answer
Follow this Question
Related Questions
Camera rotation around player while following. 6 Answers
move to a position not being looked at 1 Answer
Rotate against player when hit 1 Answer
Vector Based - Mini Map 1 Answer
Move object on local axis instead of world axis after rotation 0 Answers