Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

2D object with 3D collider or flat 3D object

Discussion in 'Getting Started' started by executor1909, Dec 23, 2016.

  1. executor1909

    executor1909

    Joined:
    Jan 23, 2016
    Posts:
    17
    I'm making a 2D game (since I'm not able to create 3d models and textures on my own), but I want objects' colliders to consider depth. So I have my 2D sprites. I tried to add a RigidBody (3D one) and a 3D collider, but it doesn't have same shape as my sprite. How can I adjust it or change my sprite to flat 3D object?

    EDIT: I probably should have been described my game better. Player moves a spaceship with accelerometer and have to avoid different obstacles (for now only asteroids). They should appear behind the spaceship and then approach to it (so I've set their Z position correctly, but I haven't realised that 2D physics doesn't consider depth). When they have same Z position as player, spaceship should be destroyed and the game is over.
     
    Last edited: Dec 23, 2016
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,355
    Use compound primitive colliders (cubes, spheres, etc.).

    --Eric
     
  3. executor1909

    executor1909

    Joined:
    Jan 23, 2016
    Posts:
    17
    But what if my sprite is irregulary shaped? Should I attach a multiple colliders to fill the whole form? Is there something like polygon collider but in 3D?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,833
    The 3D equivalent is Mesh Collider. But I think you're looking at this wrong. Go ahead and use 2D colliders, and just keep the asteroid colliders deactivated until they reach the same Z position as the player.
     
    executor1909 likes this.
  5. executor1909

    executor1909

    Joined:
    Jan 23, 2016
    Posts:
    17
    Oh, I've never thought about that. That would be actually much easier for me to achieve (I know almost nothing about 3D to be honest). I'll definitely try this, thanks! :)

    EDIT: Thanks again, works perfectly fine! That's what I've been looking for! :D
     
    Last edited: Dec 23, 2016
    JoeStrout likes this.
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,355
    Compound primitive colliders. ;) You don't generally try to get colliders to be 100% pixel exact, just close enough.

    --Eric
     
  7. angelonit

    angelonit

    Joined:
    Mar 5, 2013
    Posts:
    36
    I came upon this problems some days ago and made a unity tool that makes a MeshCollider from PolygonCollider2d.

    It's called "Polygon Collider 2D to Mesh Collider" and it's for sale on my Itch io page (if you DM me I can send you a free test)