More collision layers and masks?

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

I use all collision layers, masks and I need more of them.
Is there a solution?

:bust_in_silhouette: Reply From: Zylann

You can ask for more on github, but it is common in physics engines to have a finite amount of layers and masks, so in the worst case you will have to do some redesign in the way you use them.

You can try to optimize your use of layers by re-using them when loading different levels or contextes. For example, if in one part of the game you use layer X, but in another part it’s not used, you can re-use it for a different purpose. I had this issue in another engine where we ran out of layers but we learned to live with that limitation, which isn’t ideal but works just enough.

Also you can make your layers a bit more generic (instead of trying to catch every single case, which would make you run out of layers too quickly) and do filtering in your collision functions on a case per case basis depending on the execution cost you estimate.

Finally, you can also remove usage of layers in some cases. For example if you need to know if a player is inside a circular force field, instead of using a layer and a collision shape you can do a bit of math to calculate the distance from the shield’s center. Ideally you would go for that solution for things that don’t need much CPU resources.

I use a Tilemap and the object is unfortunately a PhysicBody that should not collide with the Tilemap. So Add_collision_exception_with() doesn’t work. And as I said all collision layers and masks are full. I really appreciate an answer, because I’ve been trying to solve the problem for months :(.

Flo | 2018-07-30 18:12