- Home /
my car isn't moving
hi, i'm just trying to learn how to use WheelCollider.motorTorque , and i saw this script somewhere around
public WheelCollider fr;
public WheelCollider fl;
public WheelCollider br;
public WheelCollider bl;
public float speed = 10.0f;
public float steerSpeed = 10.0f;
public GameObject COM;
int gear = 4;
void Start ()
{
rigidbody.centerOfMass = COM.transform.localPosition;
rigidbody.angularDrag = 10;
br.motorTorque = 30;
bl.motorTorque = 30;
}
void Update ()
{
if (Input.GetKeyDown("1"))
{
gear = 1;
}
if (Input.GetKeyDown ("2"))
{
gear = 2;
}
if (Input.GetKeyDown ("3"))
{
gear = 3;
}
if (Input.GetKeyDown("4"))
{
gear = 4;
}
}
void FixedUpdate()
{
fr.steerAngle = Input.GetAxis("Horizontal") * steerSpeed;
fl.steerAngle = Input.GetAxis("Horizontal") * steerSpeed;
br.motorTorque = Input.GetAxis("Vertical") * speed * gear;
bl.motorTorque = Input.GetAxis("Vertical") * speed * gear;
}
so i made a box and some clyinders to make them a car and an empety GameObject to be the COM and centered it to all the wheels to test this script(i didn't parent any thing)
and i tested it but the wheels doesn't move, the front wheel's WheelCollider is rotating well but it never moves, sorry for being so stupid >,< :)
You may be better off starting with the Car Tutorial, it's free on the Asset Store.
yea, i'm sure i'll check it :) , but please for now can u tell me why isn't it moving , and i'm sorry for that.
Sorry, but for me at least, it's easier to help people after they have learned something from a book. I'm lazy see. Best of luck.
Answer by vanofthedawn12 · Aug 20, 2012 at 03:10 PM
It is because you are not updating the motorTorque on the fixed update.. I imagine your car moving a bit after a torque of 30 is applied but I also think that your car is heavy to be moved by a torque of 30.... try something like 1000.0f.. just imagining, not sure if it'll work