Crouch capsule

I am trying to make a game in which the character sprints, jumps, prones, crouch. So everything seems fine until I crouch and try to go under an obstacle, the collision boundary of the character remains the same and It is unable to go underneath the obstacle. Can please someone explain me in detail how I could use two different capsules using timeline to get this done. Thank u

personally i wouldnt go with two capsules, if you wanted to go that route then you would need to get both capsules can disable the collision on one then enable collision on the other. in theory that would work but for a crouch situation i would just modify the capsules height via set capsule half height. this allows you to quickly make the capsule shorter then when done crouching just reverse the process by setting to the original height.

If you look into the character movement of the default character you can see it has a crough height collision. Pretty sure that if you set it up right, it should automaticly adjust the collision. So either you didn’t take the crouch variable from your character moment into your code, or your object is lower then the crouch height. Make sure you are communicating anything linked to crouch and speed with your character movement and adjust the crouch height if needed. Let me know if this helps :slight_smile: (It is pretty basic, but who knows :P)

I’ve tried that already but it doesn’t seem to be working. Please help me out

How are you getting your character to crouch? In order for Crouched Half Height to work, you have to specifically call Crouch and Uncrouch (to stop crouching) in your character class.

this is how my event graph looks like

according to the picture your neither using the crouch node nor setting the capsule height or switching collision volumes. given that, what are you thinking would be modifying the capsule?

did you try the solutions presented?

also if you use the built in nodes for things you will be able to eliminate the entire script you have there and just use the settings built into the character movement component.

I agree with ThompsonN13. You are doing nothing to set the height of the collision capsule, so of course your collision capsule will remain the same size if you go into crouch. Just because you made a crouch bool, doesn’t mean the engine understands what you want by it.

Your options are either to;

  1. Directly set the height of the collision capsule. This is not recommended, since setting the height of the collision capsule during runtime is never as simple as just setting the height, as you will have to take into account the new position of the collision capsule, you have to do checks whether you can uncrouch or not and a whole lot of other things.

  2. Call the “crouch” function in your character blueprint when you want to crouch, and Uncrouch when you want to stop crouching. This function already takes care of resizing the collision capsule for you (using the Crouched Half Height variable for the new size), together with all the annoying things you would otherwise have to take into account as well. This is the recommended course of action.

this is actually my first project I am working on and I am pretty new on all this so it would be of great help if u would suggest me what changes I would have to do in the event graph so that the collision boundary works as I want it to. thank you

Get a reference to self within your character and from there get the character movement. Trough there you should be able to find the actual crouch variable. I will post some code later, currently unable to go into UE4

this is all I could find , could u tell me where I would have to connect this ,eagerly waiting for the code.thank you

in the picture below i show the crouch options that can be changed in the character movement component. i also show a basic example of implementing a toggle style crouch system.

heres the basics, if you look on the left you will see that the movement component is selected, then in the details panel you see that i searched for crouch so only options for crouching should be shown. the options here should be self explanatory. crouched half height is the height of your capsule while crouched. max walk speed while crouched is the fastest the player can move, its like what you attempted in your script. walk off ledges makes it so you can fall off a ledge. and one of the most important can crouch, which allows you to well crouch.

now on to the script part. the crouch and uncrouch nodes you see here are ones that are built into the movement component so you just need to search for them. they just set the crouch state according to the options selected in the last section. the isCrouched variable you see here is also built in to the movement component, it just tells you the state of crouching base on the nodes in the last sentence. the script itself here functions as follows, when two is pressed it checks to see if your crouched, if you are (true) then it uncrouches you, if your not (false) then you go into crouch. pretty easy right.

1 Like

This does not work. I’m actually trying to do this right now, and when crouch is pressed, it completely ignores any functions that set the capsule height. I have my crouch set to 40, which is the height i want the camera, but it sets the capsule to a size of 45 (since radius is only 45) and this results in a very small circle that doesn’t cover the whole body of the player character, the head (which the AI targets) is left sticking out and they can no longer get a hit for their line trace.

I’m actually trying to do this right now, and when crouch is pressed, it completely ignores any functions that set the capsule height. I have my crouch set to 40, which is the height i want the camera, but it sets the capsule to a size of 45 (since radius is only 45) and this results in a very small circle that doesn’t cover the whole body of the player character, the head (which the AI targets) is left sticking out and they can no longer get a hit for their line trace. Is there anyway to override the capsule size? I’ve tried setting it to 80 (if I deposses and change the player in game 80 seems to be about the height I want to cover the head) and I also tried setting it to 200, to see if it would take 200 * .4 and give me 80, both result in it still setting the capsule half height to 45.

That’s because the code responsible for setting the crouch height is, as far as I remember, constantly setting the capsule height, until the button is released AND the player is not in a space anymore where uncrouching is impossible. Hence why you cannot set the capsule height during crouch.

Also, a capsule component is nothing but a slightly more advanced sphere. It can never get smaller than its radius, since at its core it’s still that sphere. If you want an actual crouch height of 40, you need to set the radius to 40 as well. Though again, during crouch this is likely impossible. What you can do is set the sphere radius before you start your crouch, or just change the radius altogether.

ThompsonN13 has answered this question twice now and the poster hasn’t marked this answered. But the in engine function can set walk speed and not have to be reset to the normal walk speed for un-crouch? thats amazing, my code got a little shorter if thats true. I have a set float before those functions. This is also my first few months with learning UE4

I also had a need to Crouch on keypress and UnCrouch on key release, so using your excellent examples I made a simplified solution that works. Hope this helps others. If you have a need for a keypress event use this as a starting point.