Slope Movement Is So Hard (unless you use Godot Engine)


Handling slope movement is actually too easy in Godot 4.

If you're making a platformer and want to add verticality to your levels, slopes are a great way to do that, especially if you have enemies that don't jump or if your player can ride a vehicle. But if you've tried adding slopes to your platformer, chances are you've encountered weird physics issues.

Why Slopes Are So Problematic

Slopes are notoriously hard to handle because they combine vertical and horizontal movement. Your character either hops when moving from an upward slope to flat ground or floats when moving from flat ground to a downward slope.

Due to gravity, your character typically slides down a slope when the player stops moving, so you need to snap it to the surface.

On top of that, if you have separate base classes for the player and enemies, the same issues apply to both. You'll need to update them every time you change something.

There are tons of videos about handling slopes, so many that some developers give up entirely and remove them from their games. Have you seen slopes in Hollow Knight? 👀

"I'm getting rid of every slope in my game and if you are a game developer, you should too."

— Kenneth, creator of Isadora’s Edge

But come on, so many classic platformers used slopes. My childhood trifecta: Mega Man X, Super Mario World, and Kirby Super Star all have slopes and handle them beautifully.

Please, skip to 3:55


Please, skip to 0:58

Please, skip to 0:57

They all feature slopes early in the game. I don't know if this was a technological flex or if it was so easy that they just used them everywhere.

The Godot 4 Solution

Godot Engine 4.0 fixes that, making slope handling ridiculously easy.

In the first chapter of the Platformer Essentials Cookbook, "Moving Character," we present the solution.

To handle slopes in Godot 4, just follow the Mise en Place section of the chapter:

  1. Add a CharacterBody2D as the scene's root node
  2. Rename the root node to MovingCharacter2D
  3. Set the Floor Snap Length long enough to reach the floor when the character is on slopes. In my case, 64.0 worked.
  4. Toggle on the Constant Speed property.

A snapshot of MovingCharacter2D‘s Inspector properties.

Then, toggle off the Collision/Layer that represents general environment collisions. We do this because this class should only detect other objects, not be detected by them. Remove it from the general collision layer used for floors, walls, ceilings, etc.

A snapshot of the MovingCharacter2D/Collision/Layer property.

After that, set up basic movement by calling move_and_slide(). Attach a GDScript and:

  1. Add variables to control the movement forces.
  2. Add a variable to control the look direction on the horizontal axis.
  3. In the _physics_process() callback, apply gravity to the velocity.y axis. For the velocity.x axis, multiply speed by direction.
  4. Call the move_and_slide() method to move the character.

The basic script looks like this before adding vertical movement (like jumping):


What About Godot 3?

If you still use Godot 3, that's fair. I also prefer Godot 3. But things work differently there. There are videos showing how to achieve similar results using Godot 3.

Both techniques work regardless of slope angle, but pay attention to Floor Max Angle. Above whatever value you define in this property, Godot will treat it as a wall and prevents movement.

This approach doesn't prevent advanced movement techniques like jump buffering, double jump, coyote time, or wall slide/jump. In fact, the Wall Jumping Character recipe builds on this approach.

You don't need duplicate classes for player characters, NPCs, or enemies. It's an extension of CharacterBody2D, so every moving character can use it as a component. In fact, that’s how we implement the Bumping Enemy, another recipe in the book.

Get Started Today

Join 528 other indie game developers who bought the Platformer Essentials Cookbook. They rated it a perfect 5-star resource. Make your dream game following battle-tested recipes and share it with us!


Get the Platformer Essentials Cookbook now and create perfectly moving characters for your classic-inspired platformer games!

Get Platformer Essentials Cookbook

Buy Now$9.99 USD or more

Leave a comment

Log in with itch.io to leave a comment.