How to make some collisionshape2d's not collide?

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

For my staticbody I have 2 collisionshape2d and when I instance the scene at the same place it causes lag because having to many collisionshape2ds in 1 place leads to a lot of collision pairs. Having 150 instances leads to 45000 collision pairs and the fps decreases to single digits. How can I make the Collisionshape2d 1 and Collisionshape2d 2 not collide which will decrease the number of collision pairs by a lot.

Staticbody
-Sprite
-Collisionshape2d 1
-Area2d
–Collisionshape2d 2

:bust_in_silhouette: Reply From: andersmmg

Depending on your setup, you could use collision layers. Most of the time this will work. Just set each to be on a different layer, and make sure you have the things it should collide with on that same layer as well.

Collisionshape2d 1 should not collide with Collisionshape2d 2. Collisionshape2d 1 should not collide with itself. Collisionshape2d 2 should not collide with itself. And then I have the player which should collide with Collisionshape2d 2 but not Collisionshape2d 1. I have doubts to this solution because I already set the layers so that Collisionshape2d 1 does not collide but they still have collision pairs.

jujumumu | 2019-08-14 04:33

Could you tell me what layer each object is on?

andersmmg | 2019-08-14 04:43

Looking further I do not think you can change the layers for collisionshape2d only for the staticbody so there is no way to make some collisionshape2d not collide. There still might be??

jujumumu | 2019-08-14 14:53

You can only change the static body layer

jujumumu | 2019-08-14 23:08

:bust_in_silhouette: Reply From: Eric Ellingson

You should probably use collision layers/masks: Physics introduction — Godot Engine (3.1) documentation in English