i was trying to do a simple detection of when my character was inside a volume of water so i tried to use a simple OnCollisionStay2D , but it doesn’t work as i expected: it only detects the collision when the object is not moving, or not falling,( the rigidbody on my player is already set on neversleep because if not it would stop to detect the collision even if it was standing still)
[SerializeField] Collider2D myBodyCollider;
private void OnCollisionStay2D(Collision2D collision)
{
if (myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Water")))
{
Debug.Log("A");
}
}
tried to put this simple code on a square object, and this was the behaviour
you can see it stops to log the A in the debug screen when the object is moving or falling, that would happen when my character tried to jump for example
the water is a simple composite collider used by the tilemap collider, but it is not the problem i already tried to substitute it with a simple big circle with a box collider in it
i would like it to detect i’m on water always while i am touching that layer, why it?s working only when the object is standing still?
i know there could be other ways to achieve this but i’m wondering why oncollisionstay is not working as i thought