Timothy Sharp

C# Need some help with Unity.

Recommended Posts

//Rotating the car
var currentRotSpeed : float;
if(reverse){
	currentRotSpeed = rb.velocity.magnitude * rotSpeed;
}else{
	currentRotSpeed = rb.velocity.magnitude * -rotSpeed;
}

rb.AddTorque(Input.GetAxis("Horizontal" + controller) * currentRotSpeed);

//Wheel Rotation
wheel[0].localEulerAngles.z = wheel[1].localEulerAngles.z = Input.GetAxis("Horizontal" + controller) * -20;

I made a 2D car game about a year ago where I did something similar to what you might want. In the above code-snippet I show you how I rotate the car based on the rigidbody's velocity and turn the wheels accordingly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now