1

I know there are a lot of questions and answers about things falling through Terrain. I did look through them but I think this one I am having is different to all the others. I am using Unity version 2019.4.15f1.

Basically, I got a cube and a terrain (no layer settings, all default). The cube has a box collider and a rigidbody with gravity enabled. The terrain is just a simple terrain (no trees, no grass, etc) with a terrain collider and a rigidbody with gravity unchecked. I would expect the cube to hit and stopped by the terrain (or move together downwards). But the cube went straight through it (the cube was at few meters above ground so I am sure the cube wasn't touching the terrain at time 0). Now, if I removed the RigidBody component from the terrain, the cube does sit on the terrain. Is this a bug? I can't think of anything that I have done wrong (Below are the screenshot of this setting). Scenario 1 - cube settings

Scenario 1 - Terrain settings

I then went on and did another test, two cubes, one on top of the other. With the same cube mentioned above, I now unchecked the gravity box within the RigidBody component. So this cube freely floats in air. Another cube directly above has the exact same settings but with gravity box checked. As expected, the top cube fall, sticked on top of the cube at the bottom and move down together. This confirms that two objects with rigidbody and collider do interact with each other. So why doesn't terrain and cube interact with each other the same way? It didn't even register any collision on triggers (I used onCollisionEnter and onTriggerEnter to check). I would greately appreciate if someone can shine some light on me.

[Update] Okay, after some digging and testing, I figured out why. Terrain does not support rigidbody (see screenshot below). In fact, I tried to apply the same on a plane as suggested as well and confirm that plane does not support rigidbody as well. So I take that as the terrain cannot take physics behaviour. You might be able to transform or rotate it but you cannot for example, have a very heavy object jumping at one end and expect the terrain to turn like a see-saw. You can reproduce the below error by just creating a default terrain from Unity, a rigidbody to it, and then check the "is kinematics box", and then uncheck the "is kinematic box". The error will then appear from the console window. I was hoping that Unity will automatically prompt this error in the inspector itself instead of me trying to fiddle around but oh well..

enter image description here

Xenos
  • 73
  • 2
  • 11

3 Answers3

0

Try checking the terrain collider two object must have a collider to not pass through it. also continous collission detection is not supported on mesh and terrain colliders when you have rigidbody in it.

Art Zolina III
  • 497
  • 4
  • 10
  • Thank you for your reply but as mentioned, both have a collider and there aren't really much to check on the Terrain Collider as there are only 3 options in it (or can you please suggest any other checking method?). Plus that doesn't answer the question on why turning off rigidbody on the terrain will make the cube sits on top of the terrain while having it on will make the cube fall through.. – Xenos Mar 09 '21 at 00:54
  • continous collision detection is not supported for plane object. – Art Zolina III Mar 09 '21 at 08:15
  • 1
    In case you are interested, please see the reason why above. – Xenos Mar 09 '21 at 11:02
0

when working with Rigidbodies there are different collisionDetectionModes. The one you chose Discrete in the Rigidbody Settings of the Cube is performant but may just go through another Rigidbody without registering the collision at high speeds which i think your cube has since its mass is quite large. You could check that by setting the detectionMode to ContinuousDynamic and reduce the mass of the cube.

For more information check: https://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetectionMode.html

  • Thank you for your comment. I did actually tried out all possible combination collision pairs between the two (i.e. discrete/continuous, continuous/continuous, continuous/contiuous dynamics, etc. I also moved the cube closer to ground and set the mass to 1, but the cube still falls through. If remove the rigidbody component of the terrain, then it sits on the terrain no matter what collision mode it is in. – Xenos Mar 09 '21 at 09:30
  • In case you are interested, please see the reason why above. – Xenos Mar 09 '21 at 11:03
  • Ah, i didnt see that there is a Rigidbody Component attached to the terrain. – Franz Wachter Mar 09 '21 at 12:35
0

i had the same problem, i had Ore that will have Box collider as trigger to check if player can mine the Ore, but because it was trigger it was falling through ground, so i added another Mesh Collider to it that wasn't trigger, or try to add mesh collider to the terrain

  • Thank you for you comment. Some other posts did suggest adding a mesh collider to the terrain as well and I actually followed and tried. I tested with the combination of terrain collider + mesh collider, terrain collider only, or mesh collider only. The cube fallw through in all cases. – Xenos Mar 09 '21 at 09:33
  • In case you are interested, please see the reason why above. – Xenos Mar 09 '21 at 11:03