- Home /
Question by
JaroslawChrobak · Aug 02, 2019 at 09:36 AM ·
collisioncollision detectioncarwheelcollider
Car wheel not detecting ground
Hello, here's my script that is attached to every wheel:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class check_ifgrounded : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
GameObject.Find("CAR").GetComponent<Driving>().wheels_grounded = GameObject.Find("CAR").GetComponent<Driving>().wheels_grounded + 1;
}
void OnCollisionExit(Collision collision)
{
GameObject.Find("CAR").GetComponent<Driving>().wheels_grounded = GameObject.Find("CAR").GetComponent<Driving>().wheels_grounded - 1;
}
}
and that's a problem: "wheels_grounded" value is always showing "0", what I'm doing wrong?
Comment
Answer by suIly · Aug 02, 2019 at 09:41 AM
One of the gameObjects that you are colliding with has to have a rigidbody attached to it in order to detect collisions.