- Home /
Is it OK to use 2D colliders with 3D models?
I'm planning on making a platformer with 3D models, but 2D orientation. Is it OK for me to use 2D colliders while using 3D models and perspective view? Will it work correctly or am I going to face some problems?
Answer by Wisteso · Jun 15, 2014 at 02:36 AM
This question should have far more information for a complete answer.
The short short answer is "yes", you can use 2D colliders with a 3D game. The long answer is that some things wont work that way, and some things will.
Detecting mouse clicks = generally fine with a 2D collider
Detecting if two objects intersect = you might have some issues with 2D colliders
Using very small collider areas = 2D colliders have some bugs that 3D colliders do not have
What do you mean by the intersect problem? I might have to define "zones" with trigger colliders, where player variables change depending on actions inside those zones. Is it a problem with 2D colliders?
That probably wont work, if you mean you'll have 3D and 2D objects colliding. See http://answers.unity3d.com/questions/580769/can-rigidbody-2d-collide-with-3d-colliders.html
Answer by Kiwasi · Jun 15, 2014 at 07:53 PM
As long as everything is done with 2D colliders you will have no problem. I have done the same thing on one of my games.
Thanks. I am thinking of trying the same thing, all 3D models to have 2D colliders.
Answer by sedativechunk · Jun 15, 2014 at 08:45 AM
I am actually making a side scroller "2.5D" game myself. It is 3D models from a side perspective. So what the other poster here said is correct. There are bugs/issues you will run into but it is possible. In all honestly, though, you might want to avoid it. I honestly have not played with a hardcore 2D game in Unity myself. But one thing I can tell you just from working with making a crosshair appear on the screen in a 3D environment with objects firing at the position of the mouse, well, it was extremely difficult and time consuming. When you are trying to make 3D objects interact with 2D objects, you get into some very complicated physics at times. Even when using Unity's simple functions, documentation, and framework, things can be very finicky and frustrating.
2D/3D mixtures generally involve "raycasting", a word in my top five most hated words of all time. Raycasting involves the tricky of where, one object that is close to you and not in 3D space has to intersect/interact with objects in a 3D space. So if you fire a rocket in 2D space on your screen and are trying to hit a 3D object -10 units on the z axis for example, you are going to have a somewhat difficult time pulling it off. If you have a lot of 3D objects but want a 2D game, what you can do is use 3D planes. Planes are 3D but you can put 2D graphics on them and they can still collide easily with other 3D objects. I even use them in my game, and they are nice because they scale with Unity units so your objects will look good on all screen sizes. The downside is that it will be somewhat difficult to get teh sizing/scale of your 2D graphics to proportion correctly on planes.
I highly recommend you experiment first before committing yourself to a game with a combination of 2D/3D collisions because some of the physics behind it can get a bit complicated. Good luck.
I see, but at first I wasn't thinking about mixing 2D and 3D colliders, I'm using 3D models, but 2D colliders on them. Appreciate your answer though, thank you :)
Technically if all the colliders in the game will be 2D then there shouldn't be any problems as far as I am aware. Adding a 2D collider to a 3D mesh should work the same as adding a 2D collider component to a 2D sprite plane. $$anonymous$$ixing 2D and 3D meshs shouldn't be a problem as long as you don't need to mix 2D and 3D collisions.
If you've got some 3D colliders, it seems easiest to avoid 2D colliders completely. Just use a thin box collider. I've used 0.1 for z and never had problems. I think a 3D plane collider is really a mesh collider, so a box will even run faster.
If it helps, Unity had 3D colliders first, and people made perfectly fine 2D games using them. Simplified 2D colliders, and 2D mode, were added later.
Answer by Owen-Reynolds · Jul 20, 2018 at 04:07 PM
The trick is remembering that colliders are used to fake where something counts as being. The way it looks and where the collider says it is are independent. This can be a little confusing, since Unity tries to add the "correct" collider to objects -- but we know we can delete the free box collider on a cube, add a sphere collider, and it works just fine. Or we can have an 3D spaceship model, but using a sphere collider (which is good enough for weapons fires and crashes.)
A basic 2D game could start with 2D colliders with colored squares moving around. Then you'd add better textures or sprites with transparency, keeping the colliders the exact same since you liked that gameplay. Or, add 3D models, also with no change to gameplay.
Answer by aklgupta · Jul 21, 2018 at 10:03 AM
As @Kiwasi has mentioned, it will be okay as long as there are only 2D colliders. I tried and tested it recently. Also, in my research, I learned that 2D colliders and 3D colliders can not interact with each other. And since we can not have both on the same game object, in case you want both to interact with one another, a workaround would be to add an empty child to any of the objects, say the 3D collider object, and use that empty object to detect any collisions with other 2D colliders.
Your answer