Restricting collisions to a node subtree

Godot Version

4.2.2 - Linux



I’m making a space themed game, where a player lives in a simulated universe. The game has a concept of star systems, which you can jump in and out, it works kind of like an instance of sorts. The thing is that I want to keep simulating these star systems even if the player is not in them.

My project features basic combat system in which ships can shoot at each other, all ships have their own hitboxes as well as bullets.

Now the main problem that I’m facing is inability to keep those star systems segregated between each other. In the beginning I was thinking to keep them in one place, turn off rendering for all of them except the one that the player is in and separate collisions based on layers, but this leaves me with max 32 star systems.

Another idea is to just separate those star systems by some arbitrary distance, so large that player is feasibly never getting to other star system by just flying there and not using a jump point but that seems a bit hacky to me.

I started wondering if there is a way to isolate collisions to a given subtree?
for example the following tree:

- StarSystem1
   - Ship1
- StarSystem2
   - Ship2
   - Bullet1

Ship1 would not collide with either Ship2 or Bullet1, but Ship2 and Bullet1 could. Is there a way to do this without using layers so that I can support more than 32 of these, without having to resort to displacing those in different places far apart?

maybe you could just delete bullets if they go too far to prevent them from reaching other star systems. Is this a 2d or 3d game?

You could segregate everything by group, and collisions of items from different groups are ignored.

I think I found some useful reference, mentioning something about a PhysicsServer2D: How to isolate the interior and exterior scenes?Scene switching - #3 by getupsii

It seems like I can create such a server (or get a default one) and then separate my collisions among different spaces?

I believe PhysicsServer2D is a built-in singleton like Input that you can’t create your own instance of. But if you just type PhysicsServer2D you can access the one that comes with the game.