Does Unity have something like a CollideWhenRigidBodyLeavesLayer method? Here is why:
My npc's have three MovementTypes: Walk, Swim, and Fly
They use a rigidbody for their movement and it works beautifully for characters that walk.
It also works nicely for characters that fly. By calling Physics.IgnoreLayerCollision(FlyingCharacterLayer, WaterLayer) Flying characters are now able to fly over water.
My question is, how can I make my swimming creature stay overlapping the Water Layer?
I have turned on Physics.IgnoreLayerCollision(SwimmingCharacterLayer, WaterLayer) So now swimming characters can overlap water.
But how do I test that my sea creature is leaving the water and create a collision here so he turns around and continues to swim instead of evolving into a walking fish...
My level (and therefore water) are generated dynamically so adding a perimeter obstacle for collision testing is not a very good option.
Also, the "ground" graphic/layer exists under the Water layer so I don't think there is a good way to test for collision with ground because my fish is overlapping the ground and water at the same time.
I hope I am missing something basic :)
Thanks!
UPDATE: I can check if my swimming character is no longer overlapping water with Physics.CheckSphere
But I can't figure out what to do from there. If I try to turn him around 180 degrees, he flips every frame and sometimes goes back to the water sometimes not...
if(Physics.CheckSphere(transform.position, 0.25f, LayerMask.NameToLayer("Water")) == false)
{
// Now I know that my fish is out of the water
// but I can not figure out how to turn him around
}