1
\$\begingroup\$

In all Unity games I saw so far, every object is either 2D (with RigidBody2D and Collider2D components), or 3D (with RigidBody and Collider components). This makes sense, but I wonder if there is any use to an object that has both (for example, both RigidBody2D and RigidBody, or both Collider2D and Collider)?

Are the worlds of 2D and 3D completely parallel and unrelated, or can they be connected somehow?

\$\endgroup\$
2
  • \$\begingroup\$ In my top-down shooter I'm using 3D world with 3D characters and colliders, although environment (obstacles and background) mostly consists of 2D sprites. In calculations I'm using 2D space because height is constant for most objects. You can effectively combine 3D and 2D objects (using orthogonal camera) inside the scene, but I can't think of an example when a single object is both 2D and 3D. Well, maybe a projectile, which consists of 2D sprite and 3D collider? \$\endgroup\$
    – Xamtos
    Jan 29, 2020 at 8:06
  • \$\begingroup\$ @Xamtouo It is not uncommon in Unity to combine 3d rendering components with 2d physics components, or 2d rendering components with 3d physics components. But that's not what the question is about. It is about combining 2d and 3d physics in the same game object. \$\endgroup\$
    – Philipp
    Jan 29, 2020 at 11:44

1 Answer 1

4
\$\begingroup\$

No, it can't.

Unity won't allow you to add both a Rigidbody and a Rigidbody2D to the same game object: enter image description here

It also won't allow you to add both a 3d Collider and a 2d Collider: enter image description here

What you can have, though, is objects with 3d colliders and other objects with 2d colliders in the same scene. But those objects won't interact with each other in any way. They will just pass through each other.

The 2d physics engine and the 3d physics engine are basically two parallel universes. The renderer can perceive both of these universes, but the two universes can not perceive each other.

But what you can of course do is communicate between 2d game objects and 3d game objects via scripts. You can use that to create interactions between objects in these two parallel universes. But you have to program those yourself.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .