- Home /
Compound colliders and player tags
Hi,
I'm currently working on a Desert Strike-esque project and we're having an issue with the colliders on the player object. Realistically, the only objects that could hit this collider are the game limits (a terrain collider), the enemy rockets, and the player's own rockets.
At the moment, the player has a box collider surrounding it and Physics.IgnoreCollision is called when instantiating a rocket to stop them exploding where it isn't wanted. The problem is that the box isn't really sufficient and when adding a compound collider to a child object I can't use IgnoreCollision on all of the colliders.
We have tried adding a mesh collider, but without it being marked as Convex (which distorts the mesh into a less useful shape than the box!) the player doesn't collide with the terrain collider.
I've considered using Layer Collision Matrix to stop the rockets hitting the player, but now that the parent Player object doesn't have a collider, the enemy units (searching by the "Player" tag) no long find the player unless I tag all of the primitive colliders, too. This does work, but I'm concerned that this could cause issues when using FindObjectWithTag when referencing the player in code, since there are now several gameobjects with this tag.
Is there another way of achieving what we're after using a compound collider, or would it be more sensible to work on the existing mesh collider to stop the distortion when marking it as Convex?
Thanks
Have you tried to just ignore the rocket by tags (in the players OnCollision methods)?
Are you confusing tags and layers? The Layer Collision System keys off the layer. The tags are strictly code: you can find a Player tag if it has no collider; and once the layer system says you has a collision, you can further check tags.
InifiBzz: the problem with checking tags in OnCollision is that the physics parts of the collision still happens -- bounces off, or "panic squirts away" if spawned inside.
Owen, no, I don't think so. I probably wasn't clear enough, sorry.
If my compound colliders are a child object and I use the Layer Collision $$anonymous$$atrix to block rocket collisions, there is no collider on the parent game object, which is needed in order to hit the trigger on the enemy unit. I'm reluctant to tag all of the colliders in the child objects with the same tag because FindObjectWithTag would produce more than one item.
What is are the triggers on the enemy? Are they giant "detect player in range" balls?
They are. I've just taken another quick look at this and the problem with creating a compound collider from a series of gameobjects is clearly that OnTriggerStay (the trigger the enemy uses to detect if the player is in range) is being passed a collider and checks if the gameobject it is attached to is the player, which it isn't.
I've tried referencing the parent object, but I'm not having much joy (col.gameobject.transform.parent, etc.).
Your answer
![](https://koobas.hobune.stream/wayback/20220613103902im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Undefind tag? 0 Answers
Layers are colliding even though they are set to ignore each other 1 Answer
Layers, parenting and collisions. 0 Answers
Detecting multiple gameobjects 1 Answer
Raycast shooting problems 1 Answer