Object moves out of own collider.

Hey there Unity Community.

Running into a snag, a picture says a thousand words so:

As you can see, the object is lower than it’s collider. This ball frequently drops in the game I’m making. I’m using a raycast to detect the ground beneath it to bring it to a halt. The object should become kinematic when the raycast hits, then become non-kinematic after it stops detecting any surface below it (the ground rotates away). Once the ball starts moving the collider seems to update to the position the ball is in. Since the ball tends to clip through the floor it’s getting stuck.


Does anyone know what could be causing this? Thanks in advance.

Be sure to check whether or not you are changing the spherical colliders Y position, this may cause issues, but if that is not the case, try this code after you change the isKinematic property:

SphereCollider.center = Vector3.zero;

This will reset the collider to the center of the ball

That’s not normally going to happen. You have to specially set things up to even make this possible (model and collider drift apart.) You probably did that by mistake. Do you have the ball and collider on different children, both moving? Two rigidbodies? As Limesta notes, changing the collider center would do it, but I think you’d know if you were doing that.

Also, pause the game and find out just what is moving. Keep trying to recenter the ball (or collider?) until you find out exactly what was set funny.

And, then, view from all around. The collider may always be wrong, but just looks correct from certain angles.

Took me a while to get it right, but I’ve solved the issue.

Had a bool which would set to true while a coroutine was running.
If the bool was true I made the ball object kinematic.
Once it sets to false it becomes non-kinematic and velocity is applied to the Y axis.
Then, if a raycast hits the level collider, the velocity of the ball is set to zero, stopping it from going through the mesh collider of the level.