Kinematic body gets stuck inside Tilemap tile

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

I have a KinematicBody2D (the player) which is able to see platforms, walls, and enemies in its collision mask. All simple collisions with these entities behave as expected. I use move_and_slide inside the _physics_process function to move both the player and the enemy.

My Tilemap tiles all have rectangle collision shapes (I’ve used grid snapping so all walls and floors are “flush”). There are no slopes.

The issue I’m having is that when an enemy bumps into the player in just the right way it can push the player into the floor or wall, where it gets stuck.

I’m not sure, but I think the reason is that I’m only handling movement in the player node’s _physics_process as a result of player input, whereas the movement into the wall is the result of a collision with another KinematicBody2D. So move_and_slide doesn’t get called (this is just a guess).

The only advice to handling this kind of issue I could find is this answer, but on the one hand there are no details for how to implement the solution, and on the other hand I wonder if there is a better, more recommended way to handle this since it seems like overkill to have to add a bunch of raycasts to the player and all enemies.

Does anyone know how I should proceed?

:bust_in_silhouette: Reply From: Emankcin

Take a look at this recipe from kidscancode. Is not exactly your situation but you can try to turn off infinite_inertia in your enemies as described in the recipe.

This was a useful link, but unfortunately it doesn’t solve my problem. I think the problem is that my player gets pushed through the floor when it is just standing there (so move_and_slide is not getting called on it because there is no movement input). Modifying the move_and_slide call of the enemy didn’t change this behaviour.

I guess I need some way to tell the player how to react when “bumped” by an enemy into a wall or floor …

Godont | 2021-03-01 20:13