Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Objects Falling Through Terrain

Discussion in 'Physics' started by vegasanx, Apr 7, 2019.

  1. vegasanx

    vegasanx

    Joined:
    Apr 7, 2019
    Posts:
    31
    I'm using Unity terrain and I have an enemy that drops an item. However, as soon as that item is spawned at the enemy's position, it falls through the ground. The item has a box collider with trigger off, a Ridigbody with gravity, and a sphere collider with trigger on (for pick up). The enemy has a (kinematic) Rigidbody, a NavMeshAgent, and a box collider as well.

    I've tried increasing the thickness of the terrain and various other things as well to no avail. If possible, I want the player (who also uses navmesh) and enemies to be able to walk on top of items if they are thin enough. But when I do that, the item falls through the ground.

    Messing with the collision detection settings helps a little bit but I can still make objects fall through by stepping on them and I don't want to put them on the highest settings for dropped items anyway.

    Edit: The layers should be colliding with each other properly (in the matrix).
     
    Last edited: Apr 7, 2019
  2. JKRibbz

    JKRibbz

    Joined:
    Oct 19, 2016
    Posts:
    1
    Hi, Just got back into programming. Turns out you require to change the floors "Layer" top right of inspector to environment/terrain. so far as long as it's lower down on the hierarchy it should collide as long as the appropriate colliders and rigid bodies are being used. Hope that helps! :)

     
  3. vegasanx

    vegasanx

    Joined:
    Apr 7, 2019
    Posts:
    31
    The problem is not that it's not colliding, the problem is that the object can be pushed into the ground and fall through it.

    I want my navmesh agents to be able to walk over these items without them being pushed into the ground and falling through it.

    It's been almost a year and I still don't have a solution to this problem...

    I have a problem with objects falling through terrain in general that I haven't been able to solve. I've even put a script on my object that I found online that uses raycasting to try and detect collisions with the ground before they happen and it helps but sometimes when two objects collide quickly, it can push them into the ground.

    It's so frustrating.
     
  4. chaseholton

    chaseholton

    Joined:
    Dec 17, 2012
    Posts:
    78
    I've been having the same problem as the OP. If I have a mesh cliff face on my terrain, and the player runs into it, they can push and slide through the terrain and fall below it. It's super frustrating. It only happens when colliding with objects intersecting the terrain though. It's weird.
     
  5. marchall_box

    marchall_box

    Joined:
    Mar 28, 2013
    Posts:
    139
    Having similar problem. any suggestions?
     
  6. Skeckulous

    Skeckulous

    Joined:
    Sep 21, 2017
    Posts:
    8
    Does this help?

    http://johnstejskal.com/wp/how-to-stop-falling-through-floors-in-unity/

    Goes into some issues you may be having as well as a few possible solutions. I'm guessing that's the issue you're having as I've been having the same issues with specific objects, when they get a bit of momentum behind them.

    Also if that doesn't help maybe this:
    https://forum.unity.com/threads/objects-falling-through-floor.469255/
     
    ribeirosamuel96 likes this.
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm running into the same problem (and the two links above do not help). In my case, we've converted the terrain to a mesh, but of course it's non-convex (and has to be). The terrain mesh is static, so collisions do happen, but not reliably; things can still be pushed through and then fall.

    One solution might be to have some way to know, with absolute certainty, what the "floor" height is at any point in the game. And then put a script on all physics objects that doesn't let them go below that. This absolute knowledge could be done via a height map, or maybe by raycasting down from some height that you know is above all terrain. Of course this approach fails when you have arches, caves, etc.

    Another solution would be to carve the terrain mesh up into sub-parts that are convex, and then using this series of convex mesh colliders instead of the single non-convex mesh collider. I have a feeling that would work reliably, because convex mesh colliders are "thick" and the physics engine always knows which way is out. But I don't know any automatic way to do that carving, and doing it manually would be very labor-intensive.

    If anybody has any better ideas, I'd love to hear them!
     
  8. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    782
    Doesn't the down ray, only hitting the ground layer, trick work?
    To always check the distance to the ground, and lerping it back when the object is about to fall through.
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That'll work in some cases, like a dropped item, but not in others, like an item pushed through the terrain while trying to avoid colliding with something else.

    For now I've decided to switch to Continuous Speculative collision detection, which isn't perfect either, but may be good enough for our game.
     
    p373r_lu57 likes this.
  10. Greenwater79

    Greenwater79

    Joined:
    Nov 20, 2021
    Posts:
    8
    I was just having the same problem with an asset that I downloaded. It was slowly sinking through my terrain. (although a kind of cool effect, but NOT what I wanted). The asset has a mesh collider on it. When I select Convex it doesn't fall through the floor anymore. I think there are holes in the mesh collider that are not registering with the terrain and it allows it to fall though. (just a newbie guess) I also tried replaced the mesh collider with a box collider (works in my case) and it doesn't fall through the terrain anymore either.