"Can Walk Off Ledge"

“Can Walk Off Ledge” ? If I set it to true, it will prevent the character to walk off a ledge. But how does this works? Is the character tracing down to see if there is a ledge under him all the time? If so, is there a event that fires when it detects and that I can use? I am making a “Ledge Grab and climbing system” and I want my character to grab the ledge when it walks off it. But I don’t want to use another trace, if the code is already doing that.

I experimented with this a bit, it seems like the player controller just detects if the capsule collider for the character is touching the ground. You can see that by walking off a ledge after setting “canWalkOffLedge” to false, the character will float off the edge if any part of the capsule is touching any part of the ground.

There is a flag that’s set as soon as the character leaves the ground though, I think it is “isInAir” or “isFalling”, can’t remember exactly. It is located in the movement component.

There is already a pretty long discussion about this sort of thing in this thread:

The CharacterMovementComponent does trace down to find the current ‘floor’ each step. The absence of a ‘floor’ after being on one and walking is a condition for walking off a ledge.
The results of the trace are available in the CharacterMovementComponent’s “CurrentFloor” member (which is exposed to Blueprint).

Thanks, that is what I need.

Well, I thought that this would be enough… But it would be nice to have an event as well. I want to call an animation when the character reaches a ledge, instead of starting to jump.

Agreed, there should be an event triggered for falling off a ledge!

Hey there. In terms of knowing “what is a ledge”, there is no engine code that does this right now. I think many users will have a very different interpretation as to what is a ledge and what is not. However knowing that you are starting to fall because you walk off a walkable surface is something we can do.

It sounds like you want to check the OnMovementModeChanged() event on Character to know that you started falling when you were previously walking (there is a PrevMovementMode variable you can check). The one thing about this however is that we don’t currently mark whether you are falling because you jumped or walked off a surface (or the surface became unwalkable possibly because the normal changed).

While you should be able to determine that distinction yourself (since you hook up the jump input), if you think this is something that would be useful we could add a notification that basically says “I’m about to start falling because I walked off” to distinguish it. In code you could simply override UCharacterMovementComponent::CheckFall() to do this, but for BPs we’d have to add an event. Let me know if you think this is something that would be useful and we can look in to it!

Actually, I don’t think you need a new event, you should be able to distinguish why you are falling (whether due to jump or not):

When movement mode changes to falling, check Velocity.Z, and if it is zero then you were walking, otherwise you are falling because you were launched/jumped. This is because we always zero Z velocity in walking mode… so that should be enough info.

If you want to do something based on what the previous floor was as well, you could also save off the CurrentFloor value each update, and then reference the old value when you start falling. You don’t want to check the current value when you’re falling because by then you have an invalid/unwalkable floor (which is why you started falling in the first place!).

Let me know how this works out!

This would be nice to have.

Right now I have this, but everytime I walk off a ledge, it says: " Walk off Ledge: FALSE Vel Z : 0.0"

It looks like you are checking Z velocity less than 0, not equal to 0?

Yes, because when the character is falling, its velocity should be less than zero, right?

Not in this case. This is a notification that you are starting to fall, meaning your velocity will be whatever it was before actually falling (in this case, the horizontal walking velocity), and on the next update gravity will be applied and you will actually start moving down. On the other hand, when you jump the Z velocity is set and then you enter falling mode (because the velocity caused you to leave the ground).

I think this should work (once you change the check to Z velocity or not). However I still think it’s worthwhile for us to add a notification when this specific case happens so you don’t have to do this sort of thing. I can think of one case where my suggestion won’t work, which is when you walk off the edge of a moving platform because we impart its velocity to your own right at that instant (so the zero Z check wouldn’t work there).

Changed to test if is equal to 0 and it works, but I also notice the moving plataform problem on my level.

In that case you’d probably want to do something fancier than just checking the velocity, like assume it was a fall off a ledge unless you triggered a jump.

I will definitely follow up to get an event added to the engine to make this easier in the future!

Thank you, Zak.

The result of this is:

Very cool!