# Car tire rotating to the incorrect direction

Hey guys, i'm having a little problem with my game. I'm creating a offroad game and the problem is with my car tires. They're rotating in the X axis, but it needs to rotate forward (Z axis). I think the problem is the script, but anyway... Well, here is the script and a video showing how is the problem:

var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;

var wheelFL : Transform;
var wheelFR : Transform;
var wheelRL : Transform;
var wheelRR : Transform;

var steer_max = 20;
var motor_max = 10;
var brake_max = 100;

private var steer = 0;
private var forward = 0;
private var back = 0;
private var motor = 0;
private var brake = 0;
private var reverse = false;
private var speed = 0;

function Start() {
rigidbody.centerOfMass = Vector3(0, -0.05, 0);
}

function FixedUpdate () {

speed = rigidbody.velocity.sqrMagnitude;
steer = Mathf.Clamp(Input.GetAxis("Horizontal"), -1, 1);
forward = Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis("Vertical"), -1, 0);

if(speed == 0) {
if(back > 0) { reverse = true; }
if(forward > 0) { reverse = false; }
}

if(reverse) {
motor = -1 * back;
brake = forward;
} else {
motor = forward;
brake = back;
}

rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;

frontWheel1.steerAngle = steer_max * steer;
frontWheel2.steerAngle = steer_max * steer;
wheelFL.localEulerAngles.y = steer_max * steer;
wheelFR.localEulerAngles.y = steer_max * steer;

wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);

}

It's Javascript. And here is the video: http://www.infosecom.net/L200-CD.avi

Sorry by my poor English, it's cuz i'm Brazillian. I'm 13.

Looks great so far, but yeah, the wheels looks a bit funny :)

I can see that you have four lines for the wheels:

wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);

Instead of setting the z-component, try setting the x-component. That is:

wheelFR.Rotate(frontWheel1.rpm * -6 * Time.deltaTime, 0, 0);
wheelFL.Rotate(frontWheel2.rpm * -6 * Time.deltaTime, 0, 0);
wheelRR.Rotate(rearWheel1.rpm * -6 * Time.deltaTime, 0, 0);
wheelRL.Rotate(rearWheel2.rpm * -6 * Time.deltaTime, 0, 0);

If its still incorrect, then try setting the y-component. Its a bit difficult to give you the correct answer, since I can't see the orientation of the axis :)

And if its still incorrect. Then just keep on asking, we are bound to get it right at some point :)

The problem could be in the axis of the object(you can change the axis)or it could be in the script so Maybe the solution is to change in the script the rotation and put it in a different axis or you just change the axis of the object. how to do this? Very simple, If you have already an empty you only go to the object that has the mesh and rotated and if you dont have an empty you add one and parent the mesh object to the empty and for last move all your script to the empty. The bad thing of this is that you have to change all the parts that says transform to car and put up a variable car.

Thanks to all that answered. Problem Solved :)