- Home /
Rigidbody Interfereing with Multi Collider Health Script
Alright, i have multiple colliders placed over my airplane object/model. The Airplane model has a rigid body attached to it so it can use the built in Unity aeroplane scripts. Each collider is housed in a Empty Game Object and it has Child_Health_Script. All colliders are housed under an Empty Game Object where the Parent_Health_Script is housed. Each impact from a rigidbody projectile to a collider calls the OnCollisionEnter() and deducts 20 points from overall health. The script works i tested it with a smaller scenareo. However, when i used it with a rigidbody on the main model/object the collisions are not being registered. Note, both the projectile and the rigidbody on the model/object are both set to ContiniousDynamic collision detection. How do i have the colliders detect the collision from the impact and why is the rigidbody sandbagging them?
Answer by Irin · Nov 16, 2019 at 03:59 AM
Thanks to everyone who replied, i figured out what the problem was a few weeks ago. Its not issue with Unity like i though it was a line of code in my OnCllisionEnter(), this line in particular, Destroy(Bullet_col.other); <- this line actually destroyed the collider of what ever object my player character collided with.
Answer by Irin · Oct 31, 2019 at 01:03 AM
Figured it out...kinda, so multiple colliders combined with a rigid body make compound colliders. As such, the main collision detection is done by the rigid body with the multiple colliders reporting to the rigid body. So there is no need to have a parent health script with children health script on colliders unless you are using just colliders. You can attach a single health script with just OnCollisionEnter() and place it with the rigid body. PROBLEM!: Well as it turns out if you go with the new method, the entire object falls through the ground, regardless of what collider is being used by the ground, primitive or mesh. Now what could be causing this issue?
I can see multiple things to try:
The old method, but your health colliders are now trigger colliders
Placing the health colliders in a different layer than the plane collider, that don't interact. Not sure if unity will even recognize this as valid.
multiple rigidbodies, attached together by joints. Allows for your plane breaking apart under too much stress
I only have one set of colliders that are used for the health script and the aeroplane controller from Unity. No do i need to make another set just for Trigger?
Your health script colliders would be triggers, while the main collider that prevents you falling through the ground would not.