+1 vote

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 moveandslide is extremely useful for this? Thanks in advance.

in Engine by (16 points)

2 Answers

+2 votes
Best answer

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)
https://github.com/godotengine/godot-demo-projects/tree/master/2d/platformer

by (7,908 points)
selected by

Okay I'll have a look. I more meant about how moveandslide 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!

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

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 moveandslide would make it simpler? Thank you!!! :)

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 https://godotengine.org/download , 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).

Thank you all so much for these responses.

+1 vote

This could help ;)

by (567 points)

Hmmm.... Okay thank you! I more meant about how moveandslide works, so what parameters it takes, and the math behind those. But thanks! ;)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.