How to stop a character from falling off the edge of a platform?

I am making a 3d Platformer game which has hovering platforms on which the player character should walk. But I do not want the player to walk of the edge of those platforms, the player should always stay inside the platform and if he tries to walk of the edge he should stop and not fall off.

What is the best way to implement that? I tried disabling the “Can Walk of Ledges” option but its not working as expected as the player still slides a little out of the edge of the platform.

I’m not on PC right now so hopefully a description can suffice.

Before the Add Movement Input nodes that are connected to your movement IA, get the x & y action values, make a vector with them using the Make Vector node, multiply it with a desired value, then get the character’s location with the Get Actor Location node, expose it’s components (by either using the Break Vector node or right clicking on the output pin and select the Split Struct Pin option), add the exposed x & y components onto our result from the multiplication, expose the components of this new result as well and make a new vector using the x & y values and set the z value to [the character’s location - (capsule component’s half height + a small value)] (you can just insert this manually you don’t need to use any nodes), after that get a Line Trace by Channel node and connect the final result to it’s End pin, and connect the Start pin the same final result but it’s z component should be greater. And finally get a Branch node, connect the line trace node’s Return Value pin into it’s condition pin and connect your Add Movement Input nodes to it’s True pin.

Hope this helps! :innocent:

Thanks for the reply, I’ll try doing this.

But is there any easier way to do it like similar to setting a Navmesh which could define a walkable area on the platform and the character can only walk on that area?

To check if you’re walking on a surface, you’d need to perform a trace from the character to straight down to the ground. There’s already an automatic trace going on even though you don’t do it yourself. The way I explained, you’re essentially recreating that trace required for movement, just a little further away. So that’s what you’d need to do in order to achieve your objective, one way or another. There isn’t a setting to adjust for this other than the capsule radius.

Hey @Ozymandias301, it’s been a while since we last heard from you! Do you have any updates on the matter?