- Home /
Make object pass through one object and bounce from another
I have two objects: enemy and wall. Is there a way to make shell pass through the enemy and bounce from the wall? As I read, triggers can pass through the enemy collider, but i can't access collision normal from Collider object. Only Collision object has this data. However I can't use collider instead trigger, because I want pass shell through enemy and detect it.
I mean shell should interact like trigger with enemy (because i want shoot through) and like collider with wall (because I need normal vector of the collision).
Answer by Zoedingl · Jun 22, 2020 at 10:54 AM
Just set the collider to trigger and instead of OnCollisionEnter() use onTriggerEnter().
Yeah, I know about this way. But if I'll use onTriggerEnter, I can't access collision normal (https://docs.unity3d.com/ScriptReference/ContactPoint-normal.html) because onTriggerEnter parameter doesn't contain this information.
Answer by fffMalzbier · Jun 22, 2020 at 11:05 AM
You can set in the projects physics settings what layer can collider with with other layers. That way you can define that your shell ignores all objects on the layer enemy and does collide with the wall.
I tried to do like this, but I want to detect shoot through (like onTriggerEnter). If I'll use layers, there is total ignoring of interactions between object. For example I want take damage to enemy, when shell shoots through it.