Search Unity

Rigid bodies still falling through

Discussion in 'Physics' started by lindgm, Oct 15, 2019.

  1. lindgm

    lindgm

    Joined:
    Jun 13, 2017
    Posts:
    9
    I know that a lot has been written about rigid bodies falling through and I have read a lot of that, but still I cannot find a solution to my problem! I first thought it was a bug in my scripts, but late tests show that the problem is there even if no scripts are executed.

    Simple Test:

    - A ground (manipulated cube, small in Y) with a box collider and a rigid body, using gravity.
    - A cube with a box collider and a rigid body, using gravity and placed a bit over the ground (in Y) at start.

    The box colliders cover the objects completely and I have also tested by doing them even bigger. The objects are not instantiated at runtime, but are created in the editor. None of them are static.

    Neither is marked "Is Kinematic". When I start the scene, the cube falls down as expected, but just passes through the ground although they hit each other. When running a similar scenario in my game, I can see that the collision is detected by looking in OnCollisionEnter, but they still passes through.

    NOTE: that this happens when I do this in my project! If I create a stand alone scene and test the cube and ground it works a expected. My Project setting for Physics are default. From this I conclude that there must be something wrong with the Project settings or something else connected to my project, that disturbs the physics, but I cannot understand what! I am using Unity 2019.2.7f2.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    You said your Physics settings are default but I would think that you have something wrong in the Layer-based collision detection. Maybe you have toggled something wrong in that checkbox matrix?

    https://docs.unity3d.com/Manual/LayerBasedCollision.html

    Double check that it's identical with a new fresh project. Just in case. And also check that your objects are in correct layer.
     
  3. lindgm

    lindgm

    Joined:
    Jun 13, 2017
    Posts:
    9
    Thanks for the suggestion! However all my objects belong to the Default layer and the matrix have all boxes marked.
     
  4. lindgm

    lindgm

    Joined:
    Jun 13, 2017
    Posts:
    9
    More information:

    If I add a cube with rigid body to a scene in my project and then just run the scene, the physics works, i.e. the cube stops when hitting the ground. However, if I start my program and come to the scene with the same cube, it falls through the ground.
     
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    I understood from what you say that you come to the scene, with this you mean that you enter to that SceneManager.LoadScene or something similar? I was just thinking if you load your thing additively or such that the settings get changed because of that... i.e. your scripts do something you didn't anticipate or something gets reset.

    You probably already did these tests:
    Check that a required RigidBody doesn't vanish for some reason.
    Check that the colliders still exist in the objects after you have loaded in the scene.
    Check that a collider doesn't get displaced from it's intended position.
    If you are using tags or anything, check that they exist too.
    Print the collision layers if possible (can't remember how you can exactly do that, would need to google).
    Check if you have anything that modifies the scene that might run in Start or otherwise executed by your game/app.
    Check if you are listening to any events that might do something.
    And check every other thing that might be needed is still in the scene.
     
    Last edited: Oct 18, 2019
  6. BenVenNL

    BenVenNL

    Joined:
    Oct 14, 2019
    Posts:
    56
    Im learning Unity at the moment. Bouncing a cube off another cube sitting in/on a flat cube surface.

    Just fiddling with scripts and forces the cube suddenly fell through the surface.

    Both the static surface and the static cube sitting on it had the same parameters. Could not figure it out, after desperately removing the rigid body from the surface my bouncing cube suddenly collided again.

    Why this worked? Don't know. Maybe it's a solution.
     
  7. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @BenVenNL I'm just guessing but there might be something that doesn't get reset when you work with an object. There was that kind of issues (still is?) with center off mass for example. You had to use code to reset / reposition it. This was one thread about it (just in case you are interested.):
    https://forum.unity.com/threads/collider-affects-hinge-joint.156502/

    Nowadays I try to print out everything I can if I even half-suspect there might be something weird happening, even if it's most likely my own mistake.
     
  8. lindgm

    lindgm

    Joined:
    Jun 13, 2017
    Posts:
    9
    I removed the rigid body from the ground and now my player does not fall through!! Thank you very much for this hint. However, this is not what the manual says, so I am not satisfied as long as I do not know why it works! Still I will use this solution until I find something better (if there is)
     
  9. lindgm

    lindgm

    Joined:
    Jun 13, 2017
    Posts:
    9
    Thanks for these good suggestions!
    I paused the game just when my character started to fall through and checked every object in the scene, RigidBody, colliders, tags, layers and the startup code for the scene. Everything was as expected. I also checked Physics.autoSimulation and that was always true during the whole execution, both before, under and after the collision. Note that the collision is reported in OnCollisionEnter, so Unity is aware of it, but still my character falls though. This is also true for all other object using gravity in the scene except those that have a frozen Y axes.