How do I rotate a Vector3 -45° around the Y axis?
Halp please
How do I rotate a Vector3 -45° around the Y axis?
Halp please
To rotate a vector around an axis, simply multiply it by the corresponding matrix.
Matrix4x4.RTS(Vector3.zero,Quaternion.AngleAxis(270,Vector3.up),Vector3.zero).MultiplyPoint(your_vector3_here);
Also I am still fairly new to using quaternions however, I believe you could multiply the vector by the quaternion as well and simplify a lot of that code.
I think you mean Matrix4x4.TRS, not RTS, but it sill doesn’t work.
What’s it supposed to do?
Return the rotated Vector3?
Set it?
Halp
Yes that is what I had meant ![]()
But as I was saying, multiplying the vector by the matrix will rotate it around the axis. Also you can use a quaternion which will be a lot simpler and faster to do.
OH
I forgot to multiply it
When I try to multiply the vector with the matrix it says Operator ‘*’ cannot be applied to UnityEngine.Vector3 D:
Also Wtf is a Quaternion and how do I create one that rotates it -45°?
How I multiply a Vector3 with a Quaternion?
The quaternion has to go first. A quaternion is just another way of representing a rotation that is usually favored over rotation matrices because they only require four components, which makes them a lot more light-weight and compact. To create one that is rotated -45 degrees, use the AngleAxis method as shown in my previous example.
Thx!
Now the camera can rotate around the marble when pressing the C key!
Alternately, just use Transform.RotateAround. ![]()