KinematicBody2D gets "glued" to StaticBody2D upon collision?

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

Hello! I hope you’re having a nice day.

I’m making a small prototype build for a project idea I have in mind(I’m only 5 minutes in) and I have a shipping container(StaticBody2D), with a Rect CollisionShape2D and a sprite.

I have basic code to move a player(kinematicBody2D) around (screenshot attached), he has a circle CollisionShape2D. I have only coded movement, no collision code aside from “move_and_slide”.

It works mostly well, except that if I run into the container, I get stuck onto it, and I can only move along the side of it(as if it were a rail, and i was a curtain) and not away from it. I can only detach from the container by jiggling at the corner of the container.

Where is my error in my program that causes the shape to be stuck inside the other shape, unable to escape?

Kindest Regards.

I cannot say this for certain so I wont call this an answer just in case someone else has a better answer but have you tried lowering the speed of your player to say 100 and seeing if you get the same issue?

Gluon | 2022-12-23 19:13

Hello! Yes, I tried lowering it to 100, and making it higher, both of the same problem. It also stuck to barrels and crates’ collision shapes. Is this a .5 glitch?

Apex | 2022-12-23 20:12

I dont think so I am using 3.5 and I didnt have this issue but I did once have a sprite which was moving so fast that it glitched into some collision shapes so thats why I asked. Sorry i am not sure what else it might be.

Gluon | 2022-12-23 20:41

Just a guess based on recently following Heartbeast’s tutorial.
You are adding the return value from move_and_slide() in position.
Shouldn’t that be stored as the new velocity?
Check out this video at about 14:50

LeslieS | 2022-12-25 22:00