- Home /
Rigidbodies "sinking" through surfaces?
So I have a spaceship set up with a rigidbody and physics objects that need to be inside the ship resting on parts of it. Instead, they sink into the floor, some falling completely through out of the ship.
After doing lots of research I've tried everything: Reducing the min penetration value does not help. Changing the mesh collider of the ship to convex is not possible because the mesh has more than 255 polygons. Changing the settings of all the rigidbodies with combinations of continuous dynamic and continuous do not help. Adding a box collider instead of a mesh collider does not help.
Enabling Kinematic on the ship's rigidbody makes things normal, but it needs to use physics because of the system I'm using.
Another strange thing is that the more rigidbodies I place on the ship the more every one of them sinks into it. I know this is a problem with the rigidbody on the ship, but is there a way to fix this? Thanks in advance!
Do you happen to have character controller and rigidbody with the same gameObject? Or is it just rigidbody with mesh collider?
Just a rigidbody and mesh Collider but I've also layered other objects with box colliders as children of the ship.
I figured out it was just the rigidbody affecting it but my ship needs to have a rigidbody...
You think that's weird ;)
http://answers.unity3d.com/questions/523983/physics-behaves-more-strangely-with-time.html
Answer by XiaoHong · Jun 17, 2013 at 04:17 AM
I have run into similar problems and after days of testing I think I know the answer. I was trying to stack rigidbodies and sometimes they "sink" into each other. The "sinking" can be caused by many reasons. The root cause is the way the physics engine works. I have theories but without examining Unity/PhysX source code they will remain theories.
Usually the problem arises from the constrains of the Rigidbodies.
(1) Always, always have objects scaled to 1,1,1. Different scales may not seem to affect the object right away, but they will come to haunt you. See here for why: Rigidbody.centerOfMass
(2) Are any of your Rigidbodies significantly heavier than others? An object with 100 mass will sink very deep into an object with 0.1 mass.
(3) In the Inspector, under Rigidbody, do you have "Freeze Position" checked for any of your axes? Check all components for this. If so, bodies will tend to "sink" in the frozen axis. This can be partially fixed by increasing the mass of the object that is sunk into. If you don't want to do that then you could try the solution under (4), though I don't think it should work.
(4) Do you have "Freeze Rotation" checked for any of your axes? If so, bodies will sink when trying to apply torque on the frozen axis. The sinking is increased the further you are from the local frozen axis and seems to increase with more objects applied, even if the objects aren't touching.
This is caused by Wikipedia Moment of inertia and the way the physics engine works with it. You could set this manually via this and this if you know what you're doing (college physics).
Or you could do what I'm currently doing: Add a Layer(google if you don't know how), name it something like "Ignore Collision" In Edit-> Project Settings-> Physics uncheck all the boxes in the Layer Collision Matrix for the Layer Ignore Collision. Now add a child object with only a collider to your spaceship, set the collider layer to Ignore Collision. Make the collider long in the direction perpendicular to the Frozen Axis. For example if Z rotation is Frozen, make the collider long in X or Y. If all rotation is frozen then just make the collider long in all axes. This might also partially solve problems mentioned in (3).
Edit: I just tried setting the Rigidbody.inertiaTensor manually and it seems to work as well. Example: If objects sink with Z rotation frozen, add a script to the object with the rigidbody
void Start () {
rigidbody.inertiaTensor = rigidbody.inertiaTensor + new Vector3(0, 0, rigidbody.inertiaTensor.z * 100);
}
This script doesn't affect the X and Y axes and sets the inertiaTensor for Z to be 101 times the original value.
If you want less sinking increase the mass or increase the 100. Since Z rotation is frozen anyway, this should not have too many side effects other than less sinking.
I like this solution better as it does not involve messing with layers and huge ghost colliders that could effect performance(not confirmed). The downside is you may forget and if you unlock the Z rotation later on, don't forget to change the inertiaTensor back or else your object will seem really heavy when rotating about Z.
Why do things sink? I think its because the freeze position/rotation option is bugged. Objects pushing on frozen objects don't realize that they are frozen, and keep pushing at the same "force" as if they weren't frozen. This force/sinking is somewhat inverse to the mass and moment of inertia stuff so increasing these decrease the sinking problem.
Brilliant! Thanks so much, I think Unity really should have done something to override this or at least warned us about it in the docs... But thanks again!
yes the inertiaTensor tweek fixed the sinking issue!
Had a cylinder with 140 mass ontop of a cube with mass 1 -> result was about 10% of the cylinder was inside the cube..
Changing cube's mass to 1000 made the issue disappear - Thanks..! :)
What happens if the terrain/floor doesn't have a rigidbody but only a collider? How would be the solution for this case? I've read somewhere that a terrain shouldn't have a rigidbody.
Answer by testuser2 · Jan 31, 2014 at 04:19 PM
Hi guys,
problem
The player, a biped character with the combination rigidbody/capsule collider sank about 20 cm into the flooring (terrain or the flooring of a house..). The character did not fall through the ground, but the feet could not be seen. The player (fbx file) was loaded from the resource folder and instantiated.
Maybe you know, that the character controller has got an optimized built in capsule collider with the parameter skin width to avoid this. But i wanted to use the rigidbody/capsuleCollider combination. By adjusting the y-value of the Center property of the Capsule Collider component in the inspector, the character could be moved up onto the ground, but this did not work by setting the y-value per script.
solution
Don't load the original fbx file. Make a prefab of your fbx file instead (drag it to the hierarchy, add a capsule collider to it and drag it back to the project folder, rename the orig fbx file). Now adjust the y-value of the capsule collider of your prefab in the inspector and load the prefab with GameObject gObj = (GameObject)Resources.Load(path..); Of course it is now not necessary to add a Capsule Collider to your character by script (be sure to comment out [RequireComponent(typeof (CapsuleCollider))], if you have this in your playerControlScript.
hope this is useful for you
have fun
Answer by Vonni · May 10, 2013 at 02:00 PM
Not really an answer, but some tips
Changing the mesh collider of the ship to convex is not possible because the mesh has more than 255 polygons.
You would not want that anyway. A convex collider is like a "wrap around" collider. Like a blanket tightly wrapped around your object.
I suggest that you use many convex colliders for this. Concave colliders are heavy and hate physics :P.
Also link the rigidbodies to the ship. (Depending on how you want them to react though).
Thank you but I can't attach rigidbodies to the ship because they need to move freely outside the ship as well
Answer by crogersKixeye · May 22, 2013 at 12:06 AM
Scaling a rigid body might cause this. In general, physics stuff should be scaled to 1,1,1. Unity should deal with this correctly (with a performance hit) but that might be worth checking.
Answer by dnmdns · Feb 01, 2017 at 09:07 AM
I am using Unity 5.5.0f3 personal i solve it by untick the "use gravity" under Rigidbody.
Your answer
Follow this Question
Related Questions
Strange Physics being applied to objects issue. 1 Answer
Two even colliders causing bounce at transition 1 Answer
Collision Issue - Walk Through Object 0 Answers
Make Ray hit own collider 1 Answer
Calculate the normal of a collider 1 Answer