Search Unity

Questions on stacking physics objects

Discussion in 'Physics' started by Simoense, Nov 25, 2015.

  1. Simoense

    Simoense

    Joined:
    Aug 19, 2013
    Posts:
    12
    Hello

    I'm trying to make a game in which players need to destroy a pre-build structure.
    To do this I'm working with the 3D physics engine and I'm using Unity 5.2.2p4 Personal.

    While building levels I keep running into troubles getting the structures stable.
    As soon as I start stacking objects they become unstable and start shifting around, sometimes they appear to be sliding on top of each other.
    These issues become more frequent when creating structures containing different kinds of objects. (materials)

    A Unity project containing 3 scenes that demonstrate these problems can be found here :
    http://www.simoenss.be/Psx/PsxTestSimoens.zip

    General information
    All objects are rectangular cuboids with the same dimensions : 0.3m x 0.3m x 1.5m
    So each object has a volume of 0,135m³.

    I have 2 kinds of objects, wood and brick.

    Wood uses a physics material with the following settings :
    Dynamic friction : 0.129
    Static friction : 0.25

    Brick uses a physics material with the following settings :
    Dynamic friction : 0.411
    Static friction : 0.45

    To find these values I consulted several websites about static and dynamic friction and how these applied to wood and brick specifically, so I assume these values are acceptable at the least.

    Note that both physics materials have a bounciness setting of 0. I did this specifically to combat the issues I was having without success.

    I use the Average method to calculate how the Frictions combine.

    Based on the shapes of my objects and the density of wood and brick I gave my wooden objects a mass of 95.85kg and the brick objects a mass of 195.75kg.
    I based my information about density on these values (dutch) : http://www.soortelijkgewicht.com/vaste-stoffen

    Objects positions are locked on the Z-axis and rotations are locked on the X- and Y-axes.

    The only force being applied is gravity.

    Scene 1
    The scene contains three towers.
    A wooden tower, a brick tower and a mixed tower.
    All three towers collapse when running the scene.

    Why is this happening?
    I would assume that if objects are stacked in the right way these kind of towers would be able to exist without falling over. What force is pushing them over?

    upload_2015-11-25_14-33-14.png

    All towers always seem to be falling in the same direction.

    Scene 2
    This scene contains 5 wooden towers.
    Each tower consists of 1 block more than the one before it.
    With each block added the towers become more unstable.
    Ultimately 5 blocks is the breaking point and the tower collapses.

    Again, I would assume that it must be possible to build these kind of towers.

    upload_2015-11-25_14-36-11.png

    Scene 3
    In this scene the structures are a bit more complex, but still nothing on the scale of what I would be wanting to build in the final version of my game.

    You'll see variations on the same tower.
    Again higher towers become more unstable.
    Towers with mixed objects also seem less stable than towers consisting of one type of object.
    No towers collapse in this examples, but the last one definitely shift around a bit before settling down.

    upload_2015-11-25_14-38-15.png

    General questions

    Are these behaviours considered issues or is this the intended behaviour?
    Is there a way to achieve what I'm trying to do here with the Unity 3D engine?
    Did I make some mistakes while setting up the physics materials / mass of my objects?

    Any insight into this problem would be very much appreciated.
     
    Habitablaba likes this.
  2. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    if you just want to make a 2d game I recommend the Collider2D and Rigidbody2D.
     
  3. Simoense

    Simoense

    Joined:
    Aug 19, 2013
    Posts:
    12
    Hello Morten, thanks for your input.

    Unfortunately enough I'm not able to go the 2D-route.
    The scenes I uploaded use an orthographic camera solely because it was an easy way to clearly illustrate the issue.
    The final product has lot's more bells and whistles and will demand a 3D approach.

    Out of curiosity I did however rebuild the tests in a 2D environment.
    To my surprise none of the issues mentioned above were present in the 2D world.

    In the image below you can see a 3D and a 2D representation of the same tower.
    The physical properties of the 3D and 2D brick blocks are the same, except that I could only work with 1 friction value in the PhysicsMaterial2D instead of the static and dynamic friction in its 3D counterpart.
    As you can see the 2D tower stands tall while the 3D one collapses upon running the simulation.
    upload_2015-11-26_9-30-52.png

    I also ran a test mixing materials and again, nothing collapses in the 2D world.
    upload_2015-11-26_9-31-25.png


    While these are the results I was hoping for, this only makes the issue I'm having more frustrating.
    I understand that the 2D and 3D physics engines used in Unity are two entirely separate things, but as an end-user the only thing I care about when choosing between a 2D or 3D environment is the amount of axes I can work with and not how the laws of physics are effected (because they shouldn't be).

    Any idea what's causing this difference in behaviour between the 2D and 3D implementations?
    Does anyone have any tips how to achieve the behaviour of the 2D tests in the 3D physics engine?

    An updated version of my test project, including the 2D scenes, can be found on the link below.
    http://www.simoenss.be/Psx/PsxTestSimoens_2D.zip
     
  4. Fu11English

    Fu11English

    Joined:
    Feb 27, 2012
    Posts:
    258
    Have you tried "Enable adaptive force" in the physics manager?

    That's supposed to help with stacking objects.

    Other than that, I would try increasing the solver iteration count, and maybe the fixed timestep.

    You may end up having to overide the physics yourself to get them stable. Like maybe when an object is stacked in the right place, lock it's rigidbody or add a joint and lock that.

    Good luck.
     
  5. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    If you're using the "Freeze" constraints on the Rigidbody you might need to increase the (Edit->Project Settings->Physics) Solver Iteration Count to 30. Avoiding the Freeze constraints all together might also remove the problem.
     
    Xain likes this.
  6. Simoense

    Simoense

    Joined:
    Aug 19, 2013
    Posts:
    12
    BBG, Morten, thanks for the input.

    I was able to fix my issues when realising I could use the 2D physics components on my 3D objects.
    So the initial solution Morten provided did solve the issues in the end.

    As I was working on reworking my scenes to include this solution I haven't tested the other suggestions yet so I can't report if those would've solved the issues as well.

    I still think it's too bad that there's such a huge difference in how the 3D and 2D physics behave, but at least I was able to solve the issues.

    Thanks again!
     
  7. neal-f-smith

    neal-f-smith

    Joined:
    Mar 22, 2014
    Posts:
    2
    Morten, I was looking for a solution to a similar problem for quite a long time. Updating the Solver Iteration Count to 30 worked perfectly thank you.