How can i rotate a Vector3 direction 45 degrees along the y axis?
So a Vector3(1,0,0) for example, would become Vector3(0.5,0,0.5).
And i cant use Transform.RotateAround, or any other Transform methos. As i am not applying this Vector3 directly to a object.
vector = Quaternion.AngleAxis(-45, Vector3.up) * vector;
That's a general case. For rotation around a world axis, it's faster/easier:
vector = Quaternion.Euler(0, -45, 0) * vector;
For (1,0,0), this results in (sqrt(.5), 0, sqrt(.5)), not (.5,0,.5), by the way. The length of the rotated vector stays constant. To achieve a squared hypotenuse of 1, you add .5, 0, and .5, not .25, 0, and .25, which would shorten your vector.
That operation is dependent on the order.
rotatedVector = Quaternion * vector OK
rotatedVector = vector * Quaternion won´t works and will launch a compiler error
You can set the your object rotation as Vector with euler like this:
Vector3 newRot = new Vector3(0f, 90f, 0f);
transform.rotation = Qauternion.Euler(newRot);
Thanks mate working great
Though I just saw it was misspelled, this is the correct spelling:
transform.rotation = Quaternion.Euler(new Vector(0f, 90f, 0f));