- Home /
Car moving in right direction.
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;
}
}
Answer by seckincengiz · Jan 07, 2014 at 12:49 PM
I assume you didn't share complete code. Try these:
Check your collider/colliders center point and make sure it is centered. Because colliders affects rigidbodies.
Check applied forces and make sure that there isn't any unnecessary forces applied.
Check your game objects' vector directions and make sure the objects in the same direction.
Hope these help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to set initial speed of vehicle 1 Answer
Wheel Collider motorTorque 0 Answers
My car spins back?? Help! 0 Answers
Wheels Are Too Much Inward 0 Answers
City traffic Lanes 3 Answers