How to write a smooth crouching script in blueprint?

Hi spaid,

I’ve been meaning to post back here with an update. Shortly after making this mechanic I had to overcome this same hurdle. Here is the solution that I came up with.

  • Create a Line Trace for Objects that traces above the players head by a set amount. I have it checking on press and release.

  • If it hits an object (mine is set for PhysicsBody & WorldStatic, which is set in the EObject Type variable) it won’t allow the player to stand.

  • I added an optional IsCrouching? variable that is set on Press & Release (this is done for a Sprinting mechanic I plan to have later).

You will notice that if you are crouched and walk out from under something you will not automatically stand up, you will need to tap crouch again to stand. This is because the Line Trace only checks on Press and Release. You could change it to check on a looped Timeline or a TickEvent using Delta Time and change this.

If you have any questions just let me know.

Cheers,

TJ