I am a unity beginner and making a simple car game. I have set the wheel collider according to this tutorial car tutorial
When i give torque the car is moving forward but also in right direction.
Here is my code
private void FixedUpdate ()
{
FL_WheelMesh.Rotate(FL_WheelCollider.rpm/60f * 360f * Time.deltaTime, 0f, 0f);
FR_WheelMesh.Rotate(FR_WheelCollider.rpm/60f * 360f * Time.deltaTime, 0f, 0f);
RL_WheelMesh.Rotate(RL_WheelCollider.rpm/60f * 360f * Time.deltaTime, 0f, 0f);
RR_WheelMesh.Rotate(RR_WheelCollider.rpm/60f * 360f * Time.deltaTime, 0f, 0f);
FL_WheelCollider.motorTorque = currentTorque;
FR_WheelCollider.motorTorque = currentTorque;
CarMovement();
}
private void CarMovement()
{
switch(carState)
{
case CarState.still :
{
currentTorque = 0;
}
break;
case CarState.accelerate :
{
if(currentTorque < maxTorque)
currentTorque += 10 * Time.deltaTime;
else
currentTorque = maxTorque;
}
break;
case CarState.deaccelerate :
{
if(currentTorque > 0)
currentTorque -= 5 * Time.deltaTime;
}
break;
case CarState.brake :
{
if(currentTorque > 0)
currentTorque -= 10 * Time.deltaTime;
else
currentTorque = 0;
}
break;
default :
break;
}
}
void OnGUI()
{
if(GUI.RepeatButton(new Rect(600, 350, 100, 50), "UP"))
{
Debug.Log("---- ACCELERATE ----- ");
carState = CarState.accelerate;
}
if(GUI.RepeatButton(new Rect(600, 450, 100, 50), "DOWN"))
{
Debug.Log("---- BRAKE ----- ");
carState = CarState.brake;
}
}