Prevent the Player from standing

In my game the player can crouch and go prone, while crawling under a ledge the player shouldn’t be able to stand up, but he can. While under the ledge if you stand your head and feet will clip into the ground and the ledge. I set up a collider over the characters head to check whether there is a ledge above the player to prevent him from standing, but after crawling under the ledge, where he should be able to stand, he won’t stand since I don’t know how to say if the boxcollider above isn’t triggered, then he can stand.

(I will add pictures and a link to a video showing what happens and the script)

Have you tried onTriggerExit yet? (C#)
It basically tells Unity that when you have left the trigger, you no longer need to be crouched.
Add a trigger collider to your ledges and change their tags to “ledge” and it should work.

private void OnTriggerExit2D(Collider2D leave)
{
if (leave.gameObject.tag == “ledge”)
{
forceCrouch = false;
}
}

Let me know if it works!

I’ll try that as soon as I can, I totally forgot about OnTriggerExit.

That worked thank you!