Timothy Sharp

C# Need some help with Unity.

Recommended Posts

Are you referring to the car wheels spinning, or that the car wheels are not moving/turning left or right as the car's steering wheel is turned?

 

You might try this link:

https://forum.unity.com/threads/car-wheels-spinning-and-or-rotating.77750/

 

 

Edited by ferrous

Share this post


Link to post
Share on other sites
6 minutes ago, ferrous said:

Are you referring to the car wheels spinning, or that the car wheels are not moving/turning left or right as the car's steering wheel is turned?

 

You might try this link:

https://forum.unity.com/threads/car-wheels-spinning-and-or-rotating.77750/

 

 

Not turning left and right

Share this post


Link to post
Share on other sites
//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