Problems rotating a wheel... localEulerAngles.x bugged?

I’ve got a problem…

I’m trying to rotate the wheels of a car according to the Rotations per minute of the wheelcollider that they are supposed to represent visually…

the wheel-mesh is a child of the wheel-collider and has this simple script on it:

function Update () {
	transform.localEulerAngles.y = transform.parent.collider.steerAngle;
	transform.localEulerAngles.x += transform.parent.collider.rpm * 0.01666 * 360 * Time.deltaTime;
}

The problem is that whatever I do the rotation gets stuck at 90 degrees in one direction and at 270 degrees in the other.

the weird thing is that this only happens for transform.localEulerAngles.x, if I use transform.localEulerAngles.z it rotates around and around and around without a problem.

The first car I made had wheels with a different local axis and there I used z and everything was fine…

A little demonstration of the problem:
http://gamegui.net/temp/vehicle_box_problem.html

Give a little gas to spin the wheel and notice how it gets stuck. then press space and see how everything works just perfect when it’s spinning around z… Is this a bug? what can I do?

I spent the whole evening trying to figure out what is wrong… any help would be greatly appreciated!

Well, my guess would be that the wheels have colliders and those colliders hit something at 90 and 270 degrees. After all, it’s pretty obvious that your rotation is working.

Try moving the wheels a little further away from the car and see if that helps.

From the documentation of Transform.localEulerAngles…

“Only use this variable to read and set the angles to absolute values. Don’t increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.”

The documentation is generally quite good. It might save a bit of frustration, too. :slight_smile:

Cheers,
-Jon

man, thanks so much! you brought me back on track.

I didn’t quite solve it with a single transform.Rotate(), but I introduced a new empty GameObject that is now responsible for steering left and right (here I set the angle with transform.localEulerAngles as i get the angle directly from the wheel-collider); the spinning is done on the wheel-mesh (with transform.Rotate) - works like a charm…