How to ensure an object cannot fall off a platform?

Godot Version

4.3

Question

Nowaday, some games make it so the player will not fall off a platform so easily. In the past, especially with a platformer game, the player could get slippery and fall off a cliff very easily.

How could we make it so suppose when a player is running around on a moving 3D solid platform, if the player object is near an edge, the player object will “cling” to the edge of the platform but can never fall off unless the player decided to jump up.

A naive solution might be to apply tiny invisible short walls on all platforms which prevent the player from falling off, but this requires adding the said walls everywhere.

Is it possible to code this? How to “block” the player to keep them on the platform they are staying on? The only way the player is allowed to move away from the platform is to jump. This is like a confirmation from the player they would like to move away and not stay on this platform anymore.

You could implement a ledge detection - usually it’s used for climbing mechanics and such, but can just as well be used for your purpose.
Try looking up on the net how to do it and if you have any issues - report back here.