move_and_slide help? simple platformer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nishan
:warning: Old Version Published before Godot 3 was released.

Can anyone help me? I want to create a simple platformer. I’m using the 2.2 alpha. I want my character to be able to jump, and move left and right. Also, double jumping would be perfect. I heard that move_and_slide is extremely useful for this? Thanks in advance.

:bust_in_silhouette: Reply From: DodoIta

This could help :wink:

Hmmm… Okay thank you! I more meant about how move_and_slide works, so what parameters it takes, and the math behind those. But thanks! :wink:

Nishan | 2017-04-20 17:03

:bust_in_silhouette: Reply From: eons

move_and_slide is just used to reduce all the common “slide” part of code on kinematic characters, the slide is needed when you move in an angle different than the normal of a surface.

Check the platformer demo that uses move_and_slide (master seems to be for Godot 2.2 legacy)

Okay I’ll have a look. I more meant about how move_and_slide works, so what parameters it takes, and the math behind those. But this will be useful nonetheless. Thank you! What do you mean “all the common “slide” part of code on kinematic characters”? Thanks!

Nishan | 2017-04-20 17:04

The common slide part is all the code after is_colliding on the kinematic characer demo.

The algorithm behind move_and_slide is not too complex, it takes full velocity vector and other information to use for slopes and walls.
https://github.com/godotengine/godot/blob/master/scene/2d/physics_body_2d.cpp#L1172

Here you can see it in use:
https://twitter.com/_eons/status/772840665545834496

And the docs (for master) http://docs.godotengine.org/en/latest/classes/class_kinematicbody2d.html#class-kinematicbody2d-move-and-slide

eons | 2017-04-20 17:30

Excellent. Thank you. The 2nd link was very fascinating. The 3rd to me was the most useful. The 1st link was a little confusing. What do you mean the common slide part? I’m pretty new in Godot so i’m just trying to get a grasp on things. The 1st link is confusing to me as I’m very new to this. Please can you explain it to me? I want to just create a basic character that can move left, right and jump. I was thinking that move_and_slide would make it simpler? Thank you!!! :slight_smile:

Nishan | 2017-04-20 19:12

The “sliding” is explained in the official docs Dodolta pointed out on the other answer, move_and_slide is supposed to do it saving a bit of code for simple movements on platformer or topdown using kinematic characters.

Download and add the demo projects Download - Godot Engine , the one called “kinematic character” has a controller script that works for many situations (like the tutorial, it does move, then slides if colliding).

In the kinematic collision demo you can see what happens with the lack of sliding along walls (move just stops and the body get stuck on the first collision).

eons | 2017-04-20 20:29

Thank you all so much for these responses.

Nishan | 2017-04-20 20:31