Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Can 2 rigidbodies interact as immovable walls to each other?

Discussion in 'Physics' started by FeastSC2, Oct 31, 2019.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    644
    Can 2 rigidbodies interact as immovable walls to each other? (rigidbodies 3D)

    I have a treasure chest and a player. They both have rigidbodies and a collider because I want them to respect the rules of gravity amongst other things.

    However I don't want the treasure chest to be pushed by the player when he comes nearby and touches the treasure chest.

    Here are the options I tried to fix this problem:
    • making the chest a trigger. => that's a problem because then the treasure chest fall right through the ground.
    • set different layers on the player and the chest and disable collisions between the two with the layer collision matrix. => the problem with this is that I want the treasure chest to not overlap with the player, I want the chest to act like it was an unmovable wall.
    • add a new gameobject and a new collider under the rigidbody of the treasure chest. make the rigidbody not interact with the player with the collision matrix and allow the new box collider to interact with the player. => This doesn't work because it seems that rigidbodies do not allow/function with 2 different layers. The additional box collider acts like it's on the same layer as the rigidbody.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,574
    If I've understood you correctly, you may try these one of these options:
    • Remove the rigidbody from the chest. This leaves the chest colliders only, which make it unmovable.
    • Mark the chest rigidbody as kinematic. This would have the same effect as the previous choice.
    • Configure a large mass in the Rigidbody. Thus, the player may touch it but not be able to move it.
     
    SparrowsNest likes this.
  3. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,919
    You can try to make the chest extremely heavy, like neutron-star dense.
    A hacky solution, but a solution.
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    644
    I did set the mass very high previously on the treasure chest, a mass of 1000. And you guys are right, the player with a small mass of 1 won't be able to move it (it actually moves a little bit but so few that one could consider it ok).

    The problem with this came the moment I created other objects with a high mass that could move. If this object touches the treasure chest it will get pushed because they both have a mass of 1000. Basically this solution has downsides but it might be ok for some games, just not mine.

    I need a solution where the object interacts like a wall with the other rigidbodies. Any other ideas?
     
    Last edited: Nov 1, 2019
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,574
    • Remove the rigidbody from the chest. This leaves the chest colliders only, which make it unmovable.
    • Mark the chest rigidbody as kinematic. This would have the same effect as the previous choice.
     
  6. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    644
    I don't understand what you're saying:
    1) remove the rigibody
    2) mark the rigibody as kinematic. If I removed the rigidbody in step1, is that 2nd rigidbody?

    I need the treasure chest to be able to use gravity and fall when there's no ground below it so being kinematic might pose a problem.
     
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,574
    Oh, ok. I had assumed that you wanted to keep it always static. Please disregard my last post.
     
  8. DiamondWolf2

    DiamondWolf2

    Joined:
    Dec 9, 2018
    Posts:
    15
    Doesn't zero mass equate to infinite mass as far as Unity is concerned?
     
  9. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    644
    I ended up having the objects that are movable at a mass of 100, the objects that can't be moved at a mass of 10000 and the player at a mass 1.
    Basically having big enough differences in mass so that these object do not mess with each other. That doesn't seem like a super solid way though. I'll use that for now but I hope to find another better way.


    No, it means it's really easy to move when I tested.
     
  10. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,574
    Zero mass is not allowed indeed. It would cause NaNs along the engine. If you specify zero (or negative) then the minimum supported mass is used (this minimum seems to be 1e-07, as per the limit in the Rigidbody inspector).