Hi,
Short version:
How can detect if one collider is inside another and not touching any of the collider borders?
Both colliders are triggers have rigid bodies. Read long version if you need more info.
Long version:
I have a 2D platformer game where my character is supposed to be able to climb ladders. I am doing this by checking when the player collider enters the ladder collider. When the player exits the ladder collider I am running OnTtriggerExit2D
. My problem is that if my player is perfectly centered on the ladder and he starts climbing, his entire collider is inside the ladder collider and since the colliders aren’t overlapping the OnTriggerExit2D
is fired.
Se the video for the problem in action:
Both the colliders are triggers and have rigid bodies. One capsule collider and one composite collider.
I know I can make the ladder collider thinner so the player always hits one of the sides, but I can’t figure out how to do that with a composite collider and it wouldn’t be a proper solution anyways.
Here is the trigger code:
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Climbable"))
{
playerController.climbing = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag("Climbable"))
{
playerController.climbing = false;
}
}
Is there a simple fix for this?
Thanks in advance!