How to scale capsule half height from the bottom up? (For an air crouch mechanic.)

(I’m pretty experienced with blueprinting, but I’m having trouble here:)

I’m trying to make an air crouch mechanic for a third person game.

The idea is that when the player jumps, the capsule half height is decreased from the bottom up, which gives the feeling that the character is lifting his legs up. (To help him get over obstacles.)

The problem I’m facing is that if I simply scale the capsule half height, it scales inwards towards the center. This causes the character’s head and torso to stick way out of the capsule.

I need the capsule to scale from the bottom up, so that the top of the capsule and the character’s head remain in the exact same place. Only the bottom of the capsule should move upwards, to match up with a leg lifting animation. (The animation is not shown in the above image, but I hope you get the idea.)

(One more thing that might be important for me to mention, idk: I have programed the capsule to scale smoothly over tick (as opposed to scaling instantly).)

have you found a way to solve this problem? i have same problem.

Yes, I got it figured out more or less, but I haven’t really perfected it. After scaling the capsule, you must teleport it upwards exactly half the value you took away from the scale. And that’s easy enough, but then you have to also teleport the character mesh some other value, and maybe the camera (it depends on what camera behavior you want). I’m sure there’s a “magic formula” to set the correct relative positions no matter what the scale.

If you want to play around with that, I highly recommend you disable gravity, and perhaps un-parent the camera (or use debug cam) so you can worry about it later. This will make it easier to see what’s going on when you test. (And make sure your character isn’t too close to geometry until you’re ready for it.)

But there’s a lot of other factors to consider, especially when scaling back to normal, we need to do a trace to make sure there is enough room, otherwise we could get stuck or clip through geometry. And if you want it to scale smoothly over time like I mentioned, that’s a bunch more complications, too many to list here.

Tell you what, I feel inspired to try and pull this of again. (I’ve gotten much better at programming since I first posted this.) I’ll see if I can make something worth sharing. But you’ll have to give me a few days, I’m busy with real life too. : )

Alright, I got something… It’s not what I’d call a finished game mechanic, but it’s functional. Because of course, the exact desired behavior will depend on what game you’re making. For example, the code that adjusts the mesh location won’t be necessary in a traditional first person style game where “floating” arms are attached to the camera’s location.

So what I’ve got here works very similar to Team Fortress 2’s manual air crouching. With this, it’s possible to jump up into tunnels that can’t be reached from the ground, which actually goes against the behavior I wanted for my own game, but might be preferred for others. I’ve also got some smooth overtime scaling implemented, but this could be considered overkill, especially for basic third person games I’d say.

Also, I’d just like to point out that there are definitely other ways to achieve this. Separate from this project, I’ve also been working on making my own “character movement component” from scratch, and I’ve realized that to achieve simply stepping up tall ledges, (while airborne or on ground,) no scaling is necessary at all. It’s just Unreal’s built-in Character that can’t step up steps higher than the under side of the capsule half height. (But I don’t mean to offend the creators at all when I say that. <3 )

Now, to share my work, I think it’ll be best if I simply share the project itself, rather than posting a bunch of screenshots or something. Then you can play around with it and copy the code you want to your own project. (After you back it up, of course.) This is my first time ever sharing a project though, so let me know if the link doesn’t work or isn’t complete or something else I may have screwed up. Just keep in mind you WILL have to do manual work yourself to get the behavior you want for your game. I’m sure you understand I’m not gonna make it for you. Lol Sorry. ¯_(ツ)_/¯

Here’s GitHub Link: https://github.com/TheStarchyPineapple/UE4ImprovedCrouch I hope this helps. <3

Oh, Thanks. But the link doesn’t work. it shows me a 404 page.
I have tried to set relative location when I jump, but it looked not good. I can see I move the mesh at that moment, and it doesn’t look as high as it used to jump.
I hope what you share today is a perfect way.

Sorry. Here, try this one: UE4ImprovedCrouch-master

Remember, there is no “perfect way” because it all depends on what you want. Don’t be disappointed so soon if it doesn’t look how you expected, because it might at least help you figure out what you need to do. If you’re familiar with Blue Prints, you shouldn’t find it too hard to adjust certain values. Also, some trivial features just aren’t there, like leg IKs to stop the character’s legs from going through the floor. There are plenty of tutorials on that already. Good luck. :slight_smile: