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

1 Answer

1

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 vecquat 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=myquatmyvec; Debug.Log(newvec); //output = (0,0,-10);