Don't allow to uncrouch under a structure

I’m fairly new to the world of Unreal Engine 5 and maybe a topic like this has already been opened, but I was wondering if there was a way to keep the player from standing up (this would result in the player getting stuck in the structure), to fix this, it would require repressing the input to crouch, but it seems a bit grotesque. Is there anything I can do? Thank you in advance.
Attached below is the blueprint for the crouching movement.

You want to execute a “capsule trace per channel”. There are video tutorials with this topic. I’ll see if I can find and share it here.

Here’s one example:

1 Like

I tried to follow the tutorial you sent me, unfortunately it didn’t really work, also I forgot to specify that the project I’m working on is in first person although the latter, I suppose, doesn’t cause many problems since the procedure is the same, another thing I want to add is that the sprint and crouch are more or less connected, let me explain better: when crouching and pressing the sprint input, the character consequently stops crouching and starts sprinting, even with the tutorial you sent me, if this action is performed, the player gets stuck.

Hi there,
You are moving forward.

If you trace a structure above while crouching, save this information as a boolean, for instance, “cannot uncrouch”. Then add this boolean as an extra condition to your sprinting logic. For instance, If is crouching AND cannot uncrouch then you can’t sprint. That said, your sprinting logic should be blocked while crouching underneath a structure.

Hope that makes sense.

Good evening,
Yes it makes absolute sense what you said, in fact it works correctly, however I ran into a bug in which once the character crouches under a structure, it remains crouched until the next crouch key input, this is probably not a bug since in the video you sent me a flip flop is used, in which a new key input is required precisely, is there any way to make this happen automatically?
I also take the opportunity to sengal another subspecies of bug, in which if you crouch too much to the edge of the structure it probably, not recognizing it as having a full block on top of it, rises up and the character gets stuck, I hope I explained myself well enough, in case below I attach a video of what I just talked about

Hi there,

Glad to know it is working. For the first question, you want to create a custom event and conect it to your flip flop node. You’ll need to call this event while crouching underneath a structure AND the hit detection turns into false after a true detection. If that makes sense.

For the second bug, you want to increase the trace diameter by setting it a little greater than the diameter of your own character caspule. Therefore, the best options are sphere trace or capsule trace (either by channel or by object, whatever you’re using now). A line trace won’t help you with edge detection.

Hope that clarifies.

Hey,

The second bug has been completely solved and I thank you infinitely for that, as for the first one, however, I am not using a flip flop node precisely so that the movement from uncrouch to crouch and vice versa is automatic, therefore, I don’t really know how to proceed, for addition, while I was running a playtest, I noticed a new issue: if you press the run input and crouch input at the same time, the character will drop down as it should, but if I release the sprint button while I am under a structure and i repress it the character will rise and get stuck I think there is a way to not have that happen, but other than that, the player movement is going on the right track.

1 Like

You’re almost there. It’s a matter of creating the blocking conditions to prevent double input. If you’re crouching AND under a structure, you shouldn’t be able to sprint at all. For this logic, you need a boolean for crouching, which I believe is a native variable from a character class. If not, you can create your own. Also, you need a “can sprint?” boolean as part of blocking logic.

If you’re crouching AND NOT under a structure, first you should uncrouch and then start to sprint.

If you are sprinting and press crouch, first set to “not sprinting” and then set to crouch.

Hope that clarifies.

Hey,

I tried to try to do what you told me but I couldn’t get anything done, I thought maybe it would be easier for you to understand my situation if I sent you a screen of the whole sprint/crouch system, so I attach it below.

I hope the screens are understandable


Hi there, don’t worry, you are almost there.
I see you are not using good coding practices as you are connecting multiple inputs directly (white flow lines). Instead you want to create custom events to serve as connectors.

I don’t have my computer here, so I would recommend you to create an “algorithm” outlining your desired logic. Just write down your steps in a logical sequence. It will make easier to see where to connect pins to.

For instance, start with begin play:

  1. Player starts the level
  2. Player moves around and, when crouch input is pressed, a branch asks if player is already crouching, if false, a custom event “crouch” is called, setting a boolean “is crouching?” to true, changing capsule half-height to 50, etc, then, player crouches.

2.1. if player moves around while crouching, and crouch input is pressed again, add a branch asking if player is crouching, if true , a custom event “uncrouch” should be called from the beginning of the code flow, emulating an uncrouch input. Then, player uncrouches
2.2. if player moves around while crouching, and sprint input is pressed, a branch asks if is crouching, if true, then a custom event “uncrouch” should be called from the beginning of the code flow, emulating an uncrouch input. Then, a second branch asks if player can sprint AND is not sprinting, if true, another custom event should be called to trigger a sprint input, right fron the beginning of sprinting flow. Then, player starts sprinting.

I hope that makes sense.

Hey,
Unfortunately at the moment I am away from home and I have no chance at the moment to test your method, but yours is a sensible reasoning, so, as soon as I have the computer at hand, I will try this as soon as possible and I’ll give you news on the development.

1 Like

Sounds good. Let me know if that works.
Keep up the good work.

Hey,

I’ve tried hard to combine something with the tips you gave me, but I’m back to square one, the general skeleton in broad strokes, is formed, only those two problems remain that I can’t solve, maybe (Regarding the bug, in which when I press the sprint button and crouch at the same time and when I’m under a structure, I release the sprint button and the player gets stuck) I’m positioning the variables incorrectly, on the other hand, as for the fact that the character remains crouching even when he does not have a structure on top of him, I really don’t know where to put my hand, although I think the principle is the same, I have tried to take apart all the nodes to recreate the whole system, but it didn’t lead to any conclusion, probably this problem is more complicated than I thought.

Hi there
Don’t give up.

Try to finish the algorithm that would help you to visualize your needs.

Hey,

I will never give up, I will try until the movement is perfect, maybe it will take years lol, I tried to build the algorithm, but I have serious doubts how I connected the nodes…

That’s great to hear. If you compare, you code looks much cleaner. It’s easier to debug as well.

I’ll take a look and share my notes here in a while.

Don’t worry, you can answer me when you have time, I have been making progress in the meantime, and although it is still not perfect, I realize that this method is much more effective and I am learning so many new things!

I am attaching the screens with my progres



1 Like

Great. Here a few notes:

  1. Input action run + branch is crouching
    If true → uncrouch → second branch
    If false → second branch

This run logic has a flaw, it always sets to run. You want to add a undo logic, I mean a “Walk” custom event. What is your preference: “press and hold” or “press to toggle on/off”?

The uncrouch can be reviewed after we finish the run input.

Hey,

Thanks for the note! I will try to implement it later.
However I would prefer the player to press and hold the input, I don’t know if this is more complicated to do.

Hi there

Glad to know it’s making sense.
Back to the input action run, if you want a press and hold logic, you want to connect a “walk” custom event to the release output.