Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by SomeGuy22 · May 09, 2013 at 08:20 PM · physicscolliderissuesinking

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!

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EmJay · May 09, 2013 at 11:00 PM 0
Share

Do you happen to have character controller and rigidbody with the same gameObject? Or is it just rigidbody with mesh collider?

avatar image SomeGuy22 · May 10, 2013 at 01:15 PM 0
Share

Just a rigidbody and mesh Collider but I've also layered other objects with box colliders as children of the ship.

avatar image SomeGuy22 · May 21, 2013 at 11:55 PM 0
Share

I figured out it was just the rigidbody affecting it but my ship needs to have a rigidbody...

avatar image meat5000 ♦ · Nov 08, 2013 at 03:27 AM 0
Share

You think that's weird ;)

http://answers.unity3d.com/questions/523983/physics-behaves-more-strangely-with-time.html

6 Replies

· Add your reply
  • Sort: 
avatar image
12
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SomeGuy22 · Jun 17, 2013 at 04:08 PM 0
Share

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!

avatar image Skyboard_Studios · Nov 08, 2013 at 03:05 AM 0
Share

yes the inertiaTensor tweek fixed the sinking issue!

avatar image Anisoropos · Apr 11, 2015 at 08:51 PM 0
Share

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..! :)

avatar image iuridosanjos · May 23, 2020 at 03:21 AM 0
Share

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.

avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SomeGuy22 · May 10, 2013 at 02:04 PM 0
Share

Thank you but I can't attach rigidbodies to the ship because they need to move freely outside the ship as well

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SomeGuy22 · May 22, 2013 at 09:16 PM 0
Share

Didn't seem to have any effect... :/

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges