How to disable crouch/prone when needed?

Hi!

I’m a newcomer considering UE4, and despite my google-fu, I haven’t been able to figure out how to disable/deny uncrouching/unproning(FPS) if the there is a mesh (with collision) above the player. Now the player just stands up and the player&camera is stuck inside the mesh. Not really what I want considering most of the game is going to be inside a cave-system where the player position plays a crucial role.

Should I make it a triggerbox and play with that or is there another way to disable a certain key(c&z) from being pressed when below the mesh? Using a volume that is.

I have basic understanding of programming but I’d like to do it inside a blueprint if possible.

If this is something you’re planning on checking for a lot, I would make two box components and place them in your capsule so that they occupy the space the character would take if standing from crouch or prone. When the input to stand is pressed, get the component, get all overlapping actors of that component (make sure you set the collision so it only overlaps with level geometry or whatever else you’re checking for), get the length of that array, and if it’s equal to zero, allow the player to stand. I use a similar method to determine if my character can run on walls.

Here’s my blueprint as an example. I check if there IS something overlapping, you would want to do everything the same EXCEPT for the > operator, you would probably want to to an = operator and compare the length of the array to 0.

http://puu.sh/cgB5G.jpg

After you have something like this, just use the return value into an if statement every time the player goes to do the movement.

Some considerations for doing it this way: Your level needs to be made up of static meshes with “generate overlap events” ticked off. This won’t work on BSPs because they don’t generate overlap events.

Let me know if I lost you at any point.

There’s a lot of ways you could implement this…There are some examples in the animation content samples that use IK re-targeting to solve a similar issue. Basically, the character could be made to stand up as high as it is able without colliding.

alternatively, you could use a trace to see if there’s something in the way under player height and set a bool, then check that bool and use it to disallow standing up from the crouch.

Hello and thanks for the tips!

But of course I’m still stuck a bit. I made the CanCrouch-function as instructed:

Below, if the branch fires off to FlipFlop from true set manually and I test it the crouching is disabled, which is great, but when set to false and wobbling under a bridge and pressing crouch to stand up, the character peeks inside the bridge.
This is my partial setup for crouch inside the MyCharacter EventGraph(flipped the nodes around a lot and arranged them like so for the pic):

18618-cancrouch2.jpg

And this is MyCharacter’s box component for CrouchStand, which I’m pretty sure is wrong(among other things):

Any hints on how to solve this would be much appreciated. Useful tutorials would help too :slight_smile:

Yeah, I just knew the problem was something so simplistic that I’d I want to stab myself in the vacuum called my brain.

EDIT: Well no.

For those perhaps having a similar issue, when you have the box components on top of your capsule, make sure to set the capsule’s collision too, (I set it to ignore the box components). I didn’t realize that until later after I posted this one.

Learn through shame.

I’m actually having a similar issue, but I have a side-scroller that you press the down button to crouch like mario style…but I’m trying to get it to jump and come out of crouch anim…- but since its being held down its constantly activating the crouch…