Jump to content
  • Advertisement
Timothy Sharp

C# Need some help with Unity.

This topic is 460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
//Rotating the car
var currentRotSpeed : float;
	currentRotSpeed = rb.velocity.magnitude * rotSpeed;
	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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!