Jump to content
  • Advertisement
Timothy Sharp

C# Need some help with Unity.

Recommended Posts

Hello. I need a script for Unity that will make a car wheel turn depending on which directions a car goes. I.E My car wheels do not move when the car moves. I mean, they move, they just do not turn.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!