I'm trying to rotate a vector with a Quaternion, constructed with Quaternion.Euler(x,y,z) it works as expected, but the problem is, rotation is done with respect to the world coordinate system, whereas I want to rotate with respect to the vector itself.
So I want to take the coordinate system as
z = vector's direction,
x = vector's perpendicular (any)
y = world y.
so my code is this :
myVector = euler * myVector;
however I need
myVector = localEuler * myVector;
so I need to calculate localEuler as a function of euler and myVector.
How can I do this ?
Thanks for any help !
I tried :
localEuler = Quaternion.Euler(euler.x * myVector.x ,euler.y * myVector.y ,euler.z * myVector.z );
it didn't work. I guess this is the dot product.
P.S.
I think this has a built-in code for Transforms : Transform.RotateAround(), but I need to do it with a Vector3, not a Transform.
I solved my issue.
My solution was this :
Quaternion.AxisAngle(angle : float , rotationAxis : Vector3);so for example, to rotate around "local" x, the
rotationAxisshould be myVector's perpendicular, which is computed like this :then the new quaternion is computed like this :
then the vector is rotated correctly :