- Home /
Weird rotation behaviour
I try to rotate a wheel i X axis based on speed and Y axis based on direction. However my code seems to work only to 90 degrees in X then stops. Help please.
wheelFL.transform.localRotation = Quaternion.Euler(wheelFL.transform.localEulerAngles.x, controller.turnPower*0.3f, 0);
wheelFR.transform.localRotation = Quaternion.Euler(wheelFR.transform.localEulerAngles.x, controller.turnPower*0.3f, 0);
wheelFR.transform.Rotate(controller.moveSpeed*factor,0,0);
wheelFL.transform.Rotate(controller.moveSpeed*factor,0,0);
wheelBL.transform.Rotate(controller.moveSpeed*factor,0,0);
wheelBR.transform.Rotate(controller.moveSpeed*factor,0,0);
Answer by diegzumillo · Nov 25, 2013 at 05:21 AM
There is a number of ways to achieve what you want. My suggestion is to make the wheel the child of some other game object. Then you only apply the velocity dependent rotation to the wheel, and the inclination rotation you apply to the parent.
But why would I need to add it to different object only if i want it to rotate on other axis. That is for sure not the way.
It's a strategy to circumvent the difficulty. The problem you have is that rotations are not commutative, that is, the order you apply rotation A and B may not give you the same orientation. This hierarchy scheme will let you achieve the effect you want, the parent object could be an empty game object, it doesn't matter.
Your answer
Follow this Question
Related Questions
Rotation math question: car movement on a cylinder 0 Answers
Turret on Tank rotating fine until I'm not flat on ground 1 Answer
Why is Quaternion.Eular only rotating in one direction? [Answered] 1 Answer
Fixing the rotation around a particular axis using Quaternions? 2 Answers
Trouble Rotating Full-Circle 0 Answers