- Home /
Collision not working!!!!
I am making a car game where i want the cars health to be reduced on collision. I applied the health script to the mesh which has a box collider on it. The only other colliders are wheel colliders. But for some weird reason, there is no collision detected!! But the same script on objects outside my cars heirarchy work perfectly!! But the moment i out the code on something INSIDE my cars heirarchy, it doesnt work again. Therefore, i think my code is perfect, but theres something else that is wrong. Someone pls help me out!!!
The main_chassis is the one that has a collider on it
Do you have colliders within colliders in your hierarchy. I had a problem with that.
I just seemed to have solved the problem partially, i applied the script onto the parent(the car itself), it detects now. But this poses another problem, because the wheel colliders are a part of the main object (car), it detects when the car is on the ground and then reduces its health...
maybe you shuld ignore reducing health when the hitted object is the ground.
void OnCollisionEnter(Collision col) {
if (col.gameObject.name != "Ground")
{
health -= 1;
}
}
O$$anonymous$$. Probably at this stage it may be good to look at a working example. Check out the Car Tutorial in the Assets store [Window > AssetsStore]. It is free. Just type in car tutorial in the search in the Assets Store.
Your answer
![](https://koobas.hobune.stream/wayback/20220613140940im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collision with steep terrain 1 Answer
The timer starts after a collision with an object 1 Answer
Move car while colliding with "ground" 2 Answers
How to make a parent object's collision not affect one of its child objects 2 Answers
Character Object Collision lowers health, knocks player backwards 0 Answers