Problems with collisions and different types of nodes (Tunelling I guess??)

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

Hello everybody, I’m new to godot engine and I came with what I think is a common problem with collisions between different type of nodes (KInematic, RigidBody, etc…) Right now I have the following nodes:

  • RigidBody2D represents a movable bush object.
  • KInematicBody2D represents the player.
  • StaticBody2D, represents the walls.

There are two problems mainly, in the first one the player push the bush object against the wall (the player also follow the object) and then this bush goes through the wall and continues his path. Another problem involves the bush keeping itself above the wall when pushed by the player, and when I move the player in the opposite direction, the bush comes along with the player, like it’s glued to him. Some other times when the bush is pushed onto the wall it swaps positions with the player. I have read that the object flying through walls may be caused by tunnelling, but the object glued to the player seems weird.

Those problems do not happen when the player pushes the object in any direction against walls and does not follow it.

My question is simple: Is there some tweaks to prevent these behaviours from happening? Or that kind of “corner” cases must be handled by code? I want to know what are the limits of the default physics engine in Godot to know what to expect from it. I have already taken chances with continuous CD or increasing the physics fps. Thanks in advance and have a nice day!


To clarify i let here a link to check the problem with the bush following the player:

Player movement code:

It is hard to imagine. Can You post some video of these issues ? And post your code please, because these are not typical issues with physics engine, it must be related to your follow function somehow

Inces | 2021-11-21 15:54

Hi, thanks for your reply! I don’t have any code related to the bush following the player, it seems like a default behavior. A couple of details: Bush is a rigidbody2D with a sprite and collision shape as well as the player but with a kinematicBody2D type and rectangle shape instead of a circle shape for collisions. The walls come from tileset objects with collision defined. My only code regarding movement is on the player, and it’s a pretty basic movement algorithm and does not have anything to do or refer in any way to the bush object.

lazarski | 2021-11-21 19:17

:bust_in_silhouette: Reply From: Inces

Ok, it is weird but I think I know what is going on. Problem lies in your basic movement algorithm :). Your player is teleporting in big chunks of distance, almost like jumping through tiles. RigidBody does not understand it as movement, it acts as player is suddenly appearing in the middle of it. So when pushed against wall rigid bush finds itself blocked by bodies everywhere around and rapidly reappears away of collision. I have no idea why does it follow player thou :slight_smile:
I have never tried to combine kinematic and rigid bodies in one scene, but it should be possible if You just make kinematic body movement more fluid and smooth. Using built in movement functions (move_and_slide or move_and_collide) with defined velocities should be enough. If it doesn’t work I would advise to use RigidBody for the player, but with subtype Kinematic.

Thanks again! I just shared the physics_process where the movement is handled. I’m using move_and_collide(). I’ll give it a try changing the player’s node type!

lazarski | 2021-11-21 20:53