- Home /
Collision functions without physical collisions
Here is my situation in a 2D game (using 2D physics). In my level I have some enemies running around and I want to make a shallow body of water that damages the player but through which the enemies cannot pass. So what I did was to setup three layers "Enemies", "Player", and "Pond" and to setup the physics collisions so that "Enemies" collide with "Pond" but "Player" does not. This will keep the enemies out but allow the player to pass over the pond. So far so good.
Now, the pond should also damage the player and so I need to be able to detect collisions between the pond and the player. The problem is that because collisions are disabled between the player and the pond layers none of the collision related functions are called (OnCollisionEnter2D, etc.). I cannot enable collisions between the pond and the player because then the player will not be able to walk over the pond and I cannot make the pond a trigger collider because then the enemies will be able to walk over it.
Is there a way I can achieve this effect without having to resort to checking for collisions manually?
Answer by getyour411 · Jan 25, 2014 at 08:02 PM
Add child object to player with a collider marked as Trigger; call OnTrigger events to only affect collider.tag = "Player" and damage player.
Yup, this worked! Had to rearrange some other things to take this into account but now everything is straightened out. Thanks for the tip!