Hi There! I’m trying to make a car game that when the car hits a wall it stops working.
The problem is that I only managed to make the upper parts of the car to stop, but the wheel colliders keep working and the car keeps going after hitting the wall.
i’ve used the C# script:
public class CarScript : MonoBehaviour
{
public float maxTorque;
public Transform centerOfMass;
private bool isDead = false;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] tireMeshes = new Transform[4];
private Rigidbody m_rigidBody;
void Start()
{
m_rigidBody = GetComponent<Rigidbody>();
m_rigidBody.centerOfMass = centerOfMass.localPosition;
}
void Update()
{
if (isDead)
return;
UpdateMeshesPosition();
}
void FixedUpdate()
{
float steer = Input.GetAxis ("Horizontal");
float accelerate = Input.GetAxis ("Vertical");
float finalAngle = steer * 41f;
wheelColliders[1].steerAngle = finalAngle;
wheelColliders[0].steerAngle = finalAngle;
for (int i = 0; i < 4; i++)
{
wheelColliders*.motorTorque = accelerate;*
_ wheelColliders*.motorTorque = maxTorque;_
_ }_
_ }*_
* void OnTrigger (Collider other)*
* {*
* if (other.tag == “wall”)*
* Death ();*
* }*
* private void Death()*
* {*
* isDead = true;*
* }*
I’m new to Unity and as you can see, I do not have much KNOWLEGDE in programming and i think i did something wrong in this script, so… any help would be appreciated.
THANK YOU
*Sorry for my english, hope you can understand.