Make KinematicBody2D not collide with StaticBody2D ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Léo_Héliantas


I have a scene with obstacles (StaticBody2D), a player and its companion (both KinematicBody2D).

I’m trying to have the companion not colliding with the obstacles, but it just won’t. Even though I put them on different layers with non-overlapping collision masks :

Player : Layer = 1, Mask =3
Companion : Layer = 1, Mask = 1
Obstacle : Layer = 2, Mask = 0

Is there a way to do that ? Am I missing something obvious ? Or should I find another way around ?

(If it’s any help, the player move through direct input and the companion follow him using a Navigation2D node that approximately coincides with the obstacles)

Thanks in advance for your help

:bust_in_silhouette: Reply From: eyeEmotion

Well, I think I know a solution, not through code but through the settings.

Every PhysicsBody has the property Collision in the Inspector. So with your node selected, go to the Inspector tab, go to PhysicsBody, click on Collision and you see several rows on Layer and Mask. A highlighted block on Layer is the layer the node is part of. A highlighted block in the Mask is on which layers it can collide with.

Hope that helps.

Thanks for your answer !

Unfortunately, it’s already what I tried. The companion and obstacles collide even though the obstacles are not on a layer that’s part of the companion’s mask, and vice versa. Sorry the question wasn’t clear enough.

Léo_Héliantas | 2020-04-25 16:57

:bust_in_silhouette: Reply From: Léo_Héliantas

I finally solved the problem by using RigibBody2D in Kinematic mode for the companion, instead of KinematicBody2D. Behaves as expected so far.