Trying to set up two kinematicbody2Ds such that objectB ignores objectA for collisions, but not vice-versa.

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

I’m trying to set up two kinematicbody2ds such that objectB ignores objectA for collisions, but not vice-versa. I thought masks would let me do this, but no luck so far.

So I’ve seen other people say:

“Collision_layer describes the layers that the object appears in. Collision_mask describes what layers the body will scan for collisions. If an object isn’t in one of the mask layers, the body will ignore it.”

I have a kinematicbody2D bullet. No layers, mask set to 1 (eventually I want the bullet to detect the player). No motion or scripting for now.
I have a kinematicbody2D arrow-key-controlled player using move_and_slide. Layer 1, mask 1.

Since the bullet has no layers, I would expect the player to not see any collisions when using move_and_slide - but I still do. Any idea what I’m doing wrong? If layers are the wrong way to do this, other suggestions would be appreciated.

:bust_in_silhouette: Reply From: RedBlueCarrots

If they bullet has no collision layers, it still might have a collision mask, likely with layer 1, so any objects that are a part of layer one will collide with the bullet.

The strategy to do one way collisions with a bullet that you want to move with move_and_slide, is to have an area node as a child of the kinematic body that detects collisions with your objectA. The area node can detect a collision with the player, and the kinematic body can detect collisions with the floor.