0 votes

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?

Godot version v3.2.1.stable.official
in Engine by (63 points)

1 Answer

+1 vote

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.

by (25 points)

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 ...

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 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 webmaster@godotengine.org with your username.