- Home /
The question is answered, right answer was accepted
Wheels Rotate or Turn, but not both
Hello!
I have problem with my wheel rotation. It works if I just make them rotate or if I just make them turn, but not both at the same time! What am I doing wrong?
public Transform wheelFLTrans;
public Transform wheelFRTrans;
public Transform wheelBLTrans;
public Transform wheelBRTrans;
void FixedUpdate ()
{
// 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);
// Steering rotation
wheelFLTrans.localEulerAngles = new Vector3 (0, wheelFL.steerAngle * 2, 0);
wheelFRTrans.localEulerAngles = new Vector3 (0, wheelFR.steerAngle * 2, 0);
}
Answer by LaireonGames · Feb 24, 2015 at 08:48 PM
Its because you are setting the steering rotation directly. Basically ona simple level you are doing this:
float x = 1;
x *= 5;
x = 3;
Its the localEurlerAngles that is your culprit here. To fix change it rotate as your other lines do and convert your steer angle from degress to Radians (Mathf.DegtoRad)
How exactly do I do that? mathf.Deg2Rad is a little unclear to me.
First hit on Google...
http://docs.unity3d.com/ScriptReference/$$anonymous$$athf.Deg2Rad.html
Just multiply your wheelFL.steerAngle etc by it and job done
wheelBRTrans.Rotate (0, wheelFL.steerAngle * 2 * $$anonymous$$athf.DegtoRad, 0);
Ah sorry my bad I thought the example was pretty clear. Basically natural angles (as I call degress) need to be convert to Pi essentially.
$$anonymous$$G a complete rotation of a circle is 2Pi so all you are really doing is relating that to 360 which is what euler angles work in
Follow this Question
Related Questions
Unity 3d(Space) Questions 1 Answer
How i can equal 2 Tranform Rotations? 1 Answer
Translate from JS to C# localEulerAngles 1 Answer
Distribute terrain in zones 3 Answers
C# Mathf.PingPong Rotate Back and Forth 2 Answers