Xenos
Xenos

Reputation: 83

Cube Falling through the terrain - Unity3D

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

Upvotes: 1

Views: 3768

Answers (3)

user15295683
user15295683

Reputation:

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

Upvotes: 0

Art Zolina III
Art Zolina III

Reputation: 507

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.

Upvotes: 0

Franz Wachter
Franz Wachter

Reputation: 81

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

Upvotes: 0

Related Questions