How can I simulate no friction in a kinematic body 2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TecoSV

Hi, I’m trying to make a game on which you can push boxes to solve puzzles, is a 2D platformer basically, but I found a problem.

When a box (that is actually a kinematic body) is between two static bodies it gets stucked in the middle(No matters which function I use, is the same behaviour with move_and_slide() and move_and_collide()).

I tried with a rigid body and it simply slides between the static bodies, totally different than the kinematic, and I would like to replicate that behaviour but using a Kinematic body.

For the type of game that it is, I need to use a kinematic body.

Any suggestions?

Thanks

There are the steps to follow if you want to replicate it, I’m using the 3.0.6 stable release.

First of all create a project and add two static bodies they can be a 32x32 image, if you want you can stretch it in the Y axis to give a better effect, separate them exactly 32 pixels in the X axis, that is the space on where the kinematic body should move.

Then create a kinematic body with a 32x32 image, and a collisionShape2D (16x16) and put the kinematic body between the two static bodies, add a script to the kinematic body, one that only has in the process function move_and_slide(Vector2(0, 50))

Script

The final scene should looks like the next one:

Final scene

After all the process you will see the problem, but replace the kinematic body with a rigidbody and you will see how it slides between the static bodies.

And that’s all, I hope somebody can help me.

I edited your post because it’s not possible to use links to Google Drive to display images (they are not direct links). It’s also recommended to paste code as text rather than an image (so people can copy it easily to test).

About your question, I see you should be using _physics_process instead of _process. However, even when I fix that I can indeed reproduce the problem in Godot 3.0.6 and Godot 3.1 alpha 1, even with pixel snapping. The only way I could fix it was to reduce the extents of the box by a small amount.

I created a new issue: Kinematic body does not move when exactly in between two static bodies · Issue #23140 · godotengine/godot · GitHub

Zylann | 2018-10-19 12:55

Thanks for the answer, I will see what can I do while an official solution for this problem is created

TecoSV | 2018-10-19 19:12