Search code examples
unity-game-enginecollision-detectionfsm

Unity3D : Collision issue with "Translate" object


I don't know why, but when I move my sphere continuously with a translation, the sphere enter a little bit inside a wall when there is a contact between the sphere and a wall..

I attached a little video, and my FSM and the inspector of my sphere.

Thank you very much for your help ...

Regards,

Anthony

my FSM : https://www.dropbox.com/s/nvohgkdvq5rd9pd/Capture%20d%E2%80%99%C3%A9cran%202014-06-12%20%C3%A0%2012.51.04.png

Inspector : https://www.dropbox.com/s/1ec3numdfx33lbp/Capture%20d%E2%80%99%C3%A9cran%202014-06-12%20%C3%A0%2012.52.15.png

Video : https://www.dropbox.com/s/kq4nfu3t6j2mprz/tile%20collision.mp4


Solution

  • Since your sphere is a rigidbody and is not kinematic, you shouldn't ever directly translate it. Instead you can move it by adding force using Rigidbody.AddForce.

    Just for clarity, a kinematic rigidbody is a rigidbody that isn't affect by physics itself, but can move other rigidbodies without opposing force. In this situation it wouldn't make any sense to use since you want the sphere to collide with objects, and be affected by gravity.

    The problem with translating the position of the object directly is that it doesn't physically move the object using the physics engine. The physics engine then has to push the object out of the box it's intersecting with. Then the next frame you are moving the sphere back into the box, and the cycle continues.

    An added benefit of adding force to the sphere using the built-in physics engine is that you get essentially real-life movement for free. You don't have to do any extra work.