Search Unity

Collider or Rigidbody on Buildings for Physics?

Discussion in 'Physics' started by clamum, Aug 26, 2019.

  1. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    I'm working on a mobile game that involves a city scene (there will be other environments later) with buildings and cars and such. My player flies and drops a ball and I want the ball to interact via physics with the objects in the scene. Pic is attached.

    I have a big, thin rectangle that I've stretched across the ground and put a box collider on it so that'll work for a ground.

    So how do I add something to the buildings and cars so when the ball hits them, it rolls off and follows physics rules? I can't figure out if I need Rigidbodys or Colliders. Also, Mesh Colliders would be ideal because there's no way in heck I'm using multiple simple Colliders to cover a building; that would take ages to do. But if I used Mesh Colliders (if Colliders are in fact the solution) then won't that be too (processor) intensive for a mobile game?

    Any help would be appreciated.
     

    Attached Files:

  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    Use colliders for the buildings (MeshCollider). Use collider (SphereCollider) with rigidbody for a ball.
     
  3. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    Thank you for the reply! When I get a chance to work on the project and try this out I will report back on how it works.

    Oh, one thing though. I thought it was inadvisable to add Colliders to objects that are moving (due to it being very resource/processor intensive)? Maybe the ball object will just need a Rigidbody?
     
  4. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    Without some sort of collider, it will just fall through the floor though. Not sure how you would be able to do it without one unless you freeze your y-axis with some script and only want to move left and right on a flat plane lol
     
  5. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    So I went ahead and selected all buildings in the scene and added a Mesh Collider to them. The falling ball has a Rigidbody attached to it as you can see from the attachment.

    I hit play and boom, the ball rolls off of the buildings! So it works. I actually did a Build and Run and tried it on my phone and the performance is smooth and perfect. Of course the game ain't done yet but at least it looks like the Mesh Colliders won't be too resource/processor intensive.

    Now I just need to add simple colliders to the other objects (fences, cars, etc).

    Thanks for your help guys!
     

    Attached Files: