- Home /
Front wheel rotates in play mode
Hello!
My front right wheel looks all right when I am in scene mode, but once I enter play mode it rotates 180 degrees and is facing inside. This is not happening to any other wheel.
The problem goes away if I delete the Steering rotation portion of the code. Can you spot the problem? Thanks in advance!
void Update ()
{
// Steering rotation
Vector3 wheelFLTransAngle = wheelFLTrans.localEulerAngles;
Vector3 wheelFRTransAngle = wheelFRTrans.localEulerAngles;
wheelFLTransAngle.y = wheelFL.steerAngle - wheelFLTrans.localEulerAngles.z;
wheelFRTransAngle.y = wheelFR.steerAngle - wheelFRTrans.localEulerAngles.z;
wheelFRTrans.localEulerAngles = wheelFRTransAngle;
wheelFLTrans.localEulerAngles = wheelFLTransAngle;
// Wheel rotation
wheelFLTrans.Rotate (wheelFL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
wheelFRTrans.Rotate (wheelFR.rpm / 60 * 360 * Time.deltaTime, 0, 0);
wheelBLTrans.Rotate (wheelBL.rpm / 60 * 360 * Time.deltaTime, 0, 0);
wheelBRTrans.Rotate (wheelBR.rpm / 60 * 360 * Time.deltaTime, 0, 0);
}
What is the original rotation of the front right wheel in scene view?
Try removing the portion when you subtract the localeulerangles z component. Just leave it as wheelFL.steerAngle.
I managed to get the front right wheel to face the right way, but the car still steers a little to the right when I start accelerating from 0.
Any idea what might cause it?
Those are wheelcollider bugs... Search around and there are many people who have the same question. Look at the related questions... BTW how did you manage to get it rotating in the right way?
I changed the front right wheel rotation from 180 to 0 and entered play mode. It still was rotated inside so I just rotated it to 180 and it was ok. Weird?
Answer by JA_555 · Dec 14, 2014 at 08:56 AM
Maybe in scene view you could have the wheel already facing inside? Then in play mode, it would do its rotation and face the right way. As for why it even does the rotation, compare the back right wheel and the front right wheel, and maybe there will be slight difference in rotation that you can spot in the inspector.
The front right wheel is facing the right way in scene view when play mode is on. Both the front right and back right wheel's rotation is set to 0,0,0.