In response to some feedback I got on my 3D platformer, I created a function to guard against falling off of edges unintentionally. I don’t want the player to run into invisible walls, but I also don’t want accidental falls (ie, occuring when the player is not platforming), which happened a lot during playtesting.
My solution is OK, but it does feel a bit like the player is sliding against an invisible wall at times. I’m wondering how other platformers address this issue (if at all)?
the default Character Movement implementation needs to be very closely tested with your speed gates, and its own settings otherwise it just looks goofy (the character just dangling in air, and even at higher speeds running in place), and more funny because unrealistic removing frustration instead of potentially falling.
do you have a fixed speed, or do you have acceleration happening (is the player able to move slowly, or is a little bit of input on joystick-Up/Right or “W”/“D” full speed instantly.
is it really that bad if they fall (not all games need edge protection, and it could be seen as guard rails by your players (technically it would be them realizing the guard rails are there as that is what we are talking about)
are you willing to modify your geometry to make your platforms a bit bigger?
or provide a drop shadow either in addition to your other shadows? sometimes it is just a matter of understanding when the character is not over ground the player will learn how far they can go.
are you sure you really need it:
are the players moving along narrow paths where they might fall with a wrong move (balance beam/log, or side of a cliff wall): Falling here should be acceptable at some point, but if it is too often then Geometry is the answer, or telling the players “just do better”
are the players not understanding that they were supposed to jump sooner to make the gap (more on this later), or they thought that you had a “Coyote time”. this could just be that they just need more time with the controls, and you don’t need to do anything.
are the players walking up to the edge to get a better look at the surroundings, or evaluate what they need to do? this is probably the strongest reason to “save players from themselves”
does your character decelerate to slowly: similar to driving a car if the breaks don’t work well enough your going to hit something.
do you want to hide things where the player is intended to just walk off the edge to get to? this is probably an anti-reason to implement it.
if there is an acceleration value you can kind cheat with an invisible wall, put a collider around the wall, and in the OnBeginOverlap() check if the Velocity of the MovementComponent (in Blueprints I think it is just GetVelocity) is over a certain value and then disable the collision with the invisible wall. This can also help in air if momentum/Velocity is preserved.
you can implement a “Coyote time”. If your character is allowed to jump from a stand still, or from flat surfaces, when you detect falling for like a falling animation start a small tenth to half second timer (you will need to play with this number) before you actually do your “falling” stuff, so within that timer don’t disable their first or only jump, and don’t play the falling animation. This way when they would fall off they have a "split second chance to save themselves. You can even build this into your level design as requiring the player to use it for very long jumps.
if they have multiple jumps only treat it as “they cannot use their first jump” until they are outside the “Coyote time” or they have actually used their first jump either within the timer, or naturally
if they are not allowed to jump in your game or section you can do kind of similar by letting them turn back, and softly pop them onto the surface. if they are within the “Coyote time” detect if the movement Vector would intersect with a wall (probably the side of a “ground”) project a line from the bottom of the capsule in that direction in the amount of the movement vector, and then another ray in that same direction like 2-5 units up. if the first 1 finds a wall (has a blocking hit) and the second one doesn’t do a tiny little teleport by that amount up, in that direction.
be careful with this one because it can be abusable for either if the player is not allowed to jump, or if their speed + the upward acceleration would delay the falling state long enough they could get up higher then expected.
there is also the method of making the edge collision geometry just slightly bigger then the visible geometry: you end up giving an invisible lip to your geometry pieces, either modifying the colliders (providing different ones, or stapling another like box with the renderer turned off to the “ground” piece)