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.
Need some help with Unity.
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
//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.