How to stop the player capsule from bouncing off corners? (Pictures included.)

How can I stop this from happening? If I could get him to instead bounce straight back down, that would be good. But what I really want is for him to smoothly slide to the side of the block, and keep the same upward momentum, much like what happens in Super Mario Bros. for example. (Yes, in SMB if you jump close to the edge of a block, it won’t break, you will slide to the side, like in the image below.)

1 Like

Excellently illustrated. I’m trying to figure out the same thing. I see a couple similar questions being asked but none of them have answers either.

Hey, thanks! Glad to hear it. I still haven’t figured out a perfect fix, but I have found some plausible workarounds:

In the character movement component, there are these two settings: “Braking Decelerating Falling” and “Falling Lateral Friction.” Setting one of those to some higher value seems to stop the capsule from bouncing away. However there are two problems with this: One, it screws up the air control I liked, I.E. the character seems to stop too sudden. (I still don’t completely understand it.) And two, the player doesn’t get enough height after hitting the edge of the block.

So, to fix the air control, we might have to find an alternative way to add movement input while airborne. So far the best solution I’ve found is to disable input altogether after jumping. It works if you want your game to have no air control, like in Assassin’s Creed, or Uncharted for example, but I wanted my game to feel more like Super Mario Bros.

I’m at the point where I’m about to just get into the actual character movement component code and roll my own direct adjustments and solutions to the way this is handled. I’m making a smash bros esque “platform fighter” and I too want some definite air control without the character bouncing off of surfaces like crazy. Sorry if you’re not a C++ programmer though. I’m not sure if whatever I come up with will be anything I’ll be able to easily explain.

Alright, unfortunately I don’t think there’s a blueprints answer to this, if that’s what you’re asking. However I’ve done some digging around and think I can at least explain how to do it through C++ for posterity.

So to start with, lets get right to the root of the “problem,” which is this blasted code in the PhysFalling() function in the UCharacterMovementComponent class in CharacterMovementComponent.cpp:

The arrow points at the line where velocity actually gets set to the new “bounced” velocity. There’s also an identical line down at line 4045 that does the same thing in the case of a collision happening after the first collision adjustment on 3995. So, that’s our culprit. The most straightforward solution is to comment out lines 3989 and 4045. Of course, we don’t want to do that in the engine code. So we have to make our own character movement component that inherits from UCharacterMovementComponent and overrides PhysFalling(), and have our character class use it instead. To do this we have to make sure our character class is using the FObjectInitializer constructor, and then we can follow [this guide here.][2]

And that’s that. The results of the call to ComputeSlideVector() at line 3983 actually does a halfway decent job of “slipping” the character up and down past inclines and edges, like the result we’re looking for. There’s a bit of “friction” to it and I don’t know if that’s some kind of actual material friction or just a peculiarity of the calculations, but its a lot better than bouncing off in crazy ways. I’m sure any clever developer can see their way to more robust solutions and alterations to this, but I think this is a pretty solid starting point. Hopefully this will help down the road.

EDIT: I almost forgot. One negative result of this is that hitting a perfectly horizontal ceiling while traveling upward will have the character just kinda “stick” against it until gravity pulls their velocity back down. This can be circumvented by implementing a check to see if the impact normal is pointing straight down. (which is to say, its Z parameter is rougly -1.0) If it is, just set the Z parameter of Velocity to 0. You can even add more wiggle room to this check, causing the engine to treat slightly angled ceilings like they’re flat ones also, if you don’t want the character “slipping” up shallow ones.

3 Likes

This sounds like what I need. :slight_smile: I don’t even mind the sound of him not bouncing down from the ceiling, I actually wanted that for my game. Lol

I’ve used programing languages before, but I haven’t delve into using C++ with Unreal yet. I’m a little busy with other things right now, so give me some time. I’ll be sure to try it out.

Thank you very much.

Hi, Darlos9D. Are you still there? Sorry, I ended up taking a looong break from developing my game, but I’m back now, and I’m ready to try out the solution you provided me. : )

But I’m having loads of trouble. How do I do the part where you said: “So we have to make our own character movement component that inherits from UCharacterMovementComponent and overrides PhysFalling(), and have our character class use it instead. To do this we have to make sure our character class is using the FObjectInitializer constructor, and then we can follow this guide?”

I’m sorry, but I’m just not sure how to start. Do you think you could help me out one more time? :3 (Or someone else.) I’m not completely clueless, so it shouldn’t take too long.

By the way, my project was originally created with the blueprints template. Is that okay?

I don’t think you can do it with blueprints I’m afraid. The guide I linked to is the only way I could find to do it, and requires you to do work in C++. Sorry :frowning:

Hello, I’m very late to the party but I’ve found that changing “Falling lateral friction” from 0 to 2 in the Character Movement Component solves this problem for me without any downside so far.

2 Likes

You can do this pretty easily in your character blueprint without having to change any code.

Add a Box collider and manually fake the collision. That way it will act exactly like if the capsule was flat on top. Works the same for the feet and preventing the annoying terrible bounce you get when you hit an edge that way as well. Just make sure to transfer the rest of the velocity and it should work very naturally.

I have seen people trying to do all kinds of stuff like casting rays and such, but you’ll get a lot of misses if you are making a 3d platformer. So I have never seen any of those methods work.

I have done this and got a pretty much perfect result and erased all that stupid bouncing around. I can get more detailed and show my setup and example vid if anyone is still trying to tackle this issue lol. I know it stumped me for a while…

1 Like

I would appreciate if you could detail the solution you have ?

I tried a box collider at the top and was hoping the ignore impulse would solve it but it looks like its something else

I put the falling lateral threshold at 10 and it did reduce the effect but I would like to eliminate it

Thanks in advance

Where’s the guide? It’s not linked.