Hello. I have a question that I find interesting. Is it possible for 2D Colliders and Rigidbody2D to have 3D like collisions, depending on where the Player is on the Z axis? So for an example let’s say my position was 1 on the Z axis, and the thing I want to collide with is the same. Then let’s say on the Z axis of 3, there was another thing that I wanted to collide with. Would it be possible to only collide with the first thing when I’m on the same Z axis as it, and then if I switched my position to 3 Z axis, then I wouldn’t collide with the first thing, instead I would collide with the second one? Hope someone can answer this.
You could just set the Collision Layer whenever the Z-value changes. Otherwise use appropriately constrained cylinders in 3D physics.
The 2D physics engine is purely 2D (it’s the Box2D engine) and has no concept of the Z axis.
–Eric
So I’ll have to resort to changing all of my Box Collider 2Ds to 3D, all my rigidbody2Ds to 3D, all my scripts to 3D, and so on? If so, is there a quick way to do it?
I’m not sure what you mean but I thought of an idea that I think goes with what your saying. Like if I was on the 1 on the Z axis, and then changed my position to 3, the colliders on the 1 Z Axis would disable, and the ones on the 3 will enable. It could work as I was already trying it, the only thing I’m worried about is how much it will affect the performance.
You can set up Collision Layers which determine which colliders can collide with each other. See here and here for 2D-specific.
have a look at sorting layers with regards to rendering 2D scenes. that way you can swap players sorting layer, and have your player have a pseudo 3D feel.
works a bit like old school parallax backgrounds if thats the kind of feel your after. then like Pyrian says have a wee look at collision layers.