- Home /
Rotate Object Around Local X Axis , then Local Y Axis, then Local Z Axis (like a turtle)
Hello! I am having trouble getting my gameobject to rotate in the manner I would like.
I would like my gameobject to act kind of like a turtle from a drawing program, where I could input a Vector3 like (10, 25, -5) and then it would rotate around its x axis by 10 degrees. Then rotate around it's Y axis by 25 degrees, and then rotate around it's z axis by -5 degrees.
Here's a picture example: (rotations not exact)
The problem is that the axes (the green, blue, and red gizmos you see when you have an object selected) change direction as the "turtle" goes through the Vector3.
It seems like transform.Rotate(new Vector3(10,25,-5), Space.Self) should be what I'm looking for. But it doesn't give me the result I would like! It still seems to rotate around it's start up, right, and forward vectors.
public Vector3 rotation;
Quaternion zero = new Quaternion(0,0,0,1)
void Update()
{
transform.rotation = zero;
transform.Rotate(rotation, Space.Self);
}
I have also tried doing some things with Quaternions to get the desired result, but I can't figure out exactly what is need. If anyone has any advise it would be greatly appreciated!
You may want to read more about Local Space and Space World