2D collisions only if same Z level?

Hi, im sorry if there is some answer to this. I would like to resolve 2d collisions only if objects have same z value, is there some easy way to do that?

Context: For example I would like to make server/client app from space environment, each client will be in some/different ship and theese ships could be in different star systems. Now i would like from server to manage all systems simultanously, so i will give each to own group (empty object) and on different Z level. So all systems will be on same coords starting from center (0,0,x) and inner mechanics would be resolved for each system separatly (only objects with same Z position will interact).

I hope you understand what i was trying to say, sorry for my english, its not my primary language and some things are still hard to explain :slight_smile:

PS: I must admit its first time im playing with unity net support so if there is some easier way how to handle multiple “maps” (there would not be technicaly in different maps, im planning to generate them randomly at game start, i just want them to use same coordinates and from system to system i will use some sort of automatic transition) at once im open to new solutions :slight_smile:

You can limit collisions between different Unity layers. These are not the Sorting Layers, but the User Layers, which can be accessed from a game object’s inspector panel. They are located under the game object’s name, to the right of “Tags.” You can create your own layers, but only up to 24, meaning that 24 different collisions between layers can be handled. You would use

Physics2D.IgnoreLayerCollision(layerA, layerB, true)

to disable collisions between layers.

Thx for answer … i thought there will be something like that but its somehow unpractical, especialy if there will be more than 24 systems generated even if i will not need theese layers for something else too. Maybe there is some way how to simulate “z level” layers for collisions by that but im sure it would create lot of mess in my project. Maybe i will have to do that anyway but i will wait if somebody could provide easier solution :slight_smile:

So you want them to collide if their z axis match but not if they are out by even 0.0000000001?
If it’s 2d & they normally interact I was taught that you put them on the same z coords & use layers & tags to help filter interactions & use the drawing layers to determine what appears in front or behind the other.

You can use 3D physics instead of 2D. 2D physics have no concept of a Z dimension at all.

–Eric

1 Like

Oh, i see … i hoped there would be some option how layer 2d scene using z axis. Too bad, it seems more intuitive to me than that pseudolayers unity offers :confused: … If there is no easy workaround it would be maybe better to forgot security and test collisions client side then.

About 3d physics - its even capable of registering collisions with objects with zero thicknes?

You’d be using 3D physics, so you wouldn’t have objects with zero thickness. What you’re displaying on the screen is separate from how physics are calculated. i.e., use a box (cube) collider with a sprite, no problem.

–Eric

1 Like

Ok, its not ideal but it seems like my best option … thx, i will try that :slight_smile:

How would you use 3D colliders with 2D Tilemaps, any good workaround?