Need some help with Unity.

Started by
4 comments, last by MisspeldGames 6 years, 7 months ago

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.

Advertisement

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/

 

 

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

Then you should take a look at the car physics tutorials


//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.

Currently developing Ballimals.

This topic is closed to new replies.

Advertisement