[Solved] Stop player and npc’s from walking off platform edges

How do I stop the player and npc’s from walking off a platform’s ledge?

The player or npc should stop at the edge of a platform if there is no platform in front of them.

(Future plans: If they’re trying to get to the other side but can’t, they are supposed to wait for 5 seconds and then get the player’s attention to build a bridge. Then the camera will center on the character who is stuck. There is no jumping or climbing ledges in the game)

Right now, the player is colliding with the object I set as the platform, but as soon as they walk off the platform they stop and won’t go any further or back. I did not give them gravity as I do not want them falling off.

You could place a small collider (hidden sprite)- object at the edge of the platform and make the NPC stop or walk back when colliding with the object. You can see how it works in the old platformer example: GDevelop 5 (The hidden sprites are not used to keep the enemies on platforms here but the principle is the same).

1 Like

Right, I totally forgot about that. Thanks!

1 Like