move_and_slide
Sliding is a very common option for collision response. Imagine a player moving along walls in a top-down game or running up and down slopes in a platformer. While it's possible to code this response yourself after using move_and_collide(), move_and_slide() provides a convenient way to implement sliding movement. When using this method, the body will automatically slide along the colliding surface. In addition, sliding collisions allow you to use methods like is_on_floor() to detect the orientation of the colliding surface.
Since this project will require not just moving along the ground, but also running up and down slopes, move_and_slide() is going to play a large role in your player's movement. You'll see how it works as ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access