- Home /
How does Transform.Rotate actually work?
I've been trying to create a custom ragdoll system, which simply takes the jointed physics representation of the character and positions and rotates the bones of the visible character to match, but I've been having a lot of trouble.
I tried different methods of getting it all to work. I started out with this:
BoneRoot.transform.rotation=Quaternion.identity;
But as per my other question, it still wasn't working, so I started experimenting. I discovered that if I did this:
BoneRoot.transform.Rotate(-BoneRoot.transform.eulerAngles,Space.World);
BoneRoot.transform.Rotate(Root.transform.eulerAngles-Root_RotOffset,Space.World);
It spun around wildly, which seems wrong. Then I found this post. Before seeing the accepted answer to that question, I believed that using Transform.Rotate
with Space.World
would rotate the object around World axes, regardless of the object's current angle, and using Space.Self
would rotate from the object's current angle. After reading that post I'm not so sure. Does it rotate as though the pivot was at the world's centre or what?
All I want to do is set the angles of one object to that of another with an angle offset. Why is this so difficult?
My question is this: How does Transform.Rotate
actually work? I.e., what are the specific differences and workings of Space.Self
and Space.World
?
Actually, what I really want to know is why doesn't this:
BoneRoot.transform.Rotate(-BoneRoot.transform.eulerAngles,Space.World);
...set the angles to 0? Why not?? Why are rotations in Unity so complicated? I've never had this much trouble with rotations ever before!
The pivot is the same but the axis is different. For example:
transform.Rotate(0,speed * Time.deltaTime, 0, Space.World);
...rotates around the world up axis...Vector3.up. But:
transform.Rotate(0,speed * Time.deltaTime, 0, Space.Self);
...rotates around the up axis of the object...transform.up.
Did you try setting the rotation to root bone's rotation directly? transform.Rotate(x,y,z); will add x,y,z degrees per call.
@robertbu That's what I thought, but I'm still not sure if that's what I'm seeing.
@xortrox Yes. I tried BoneRoot.transform.rotation=Quaternion.Euler(Root.transform.eulerAngles-Root_RotOffset);
but I still see the same thing. sigh ...yet more experimenting to do....WHY IS THIS SO DIFFICULT?!
@xortrox Indeed I have!! $$anonymous$$y problem is solved! :D Aren't I just brilliant? ;) Now, if only I'd been brilliant hours ago I could have saved myself all this bother... :P I'll post an answer to this question in a $$anonymous$$ute, but for a more detailed explanation of my solution, have a look at the answer to my other question.
Answer by Clonkex · Apr 21, 2014 at 02:26 PM
So it turns out a lot of my problems were caused by the fact that I didn't understand fully how Eulers are really annoying and bad. Now I do, and I have a solution to my root problem. See the answer to my other question for how I solved my problem.
To give a quick overview: Don't use Eulers. It turns out they really can be stupid and annoying. Now I understand why Quaternions are so good.