I’ve created a game object and added a rigidbody to it. In the scene editor/viewer I set its position to 0, 10, 0. And it is scaled to 1, 2, 1. Next, I changed the position of another game object (the floor) to 0, -.05, 0.
After I clicked on the play button, the game object falls down (due to the gravity). After it hits the floor, it does nothing else, which is normal.
I then noticed that the y-axis of its position is not exactly 0 but rather 0.48 and it doesn’t change unless I change the y-axis of the floor’s position. Can you please explain why? How can we fix it?
Two things:
-
How thick is the floor’s collider? What is the collider y-centering? What kind of collider does the player have? Some are taller than others, or scale funny (spheres, if not all scales the same.) Finding the exact top of the floor collider, or exact bottom of yours, often requires some math.
-
The physics system allows (and, I think, requires) objects to interpenetrate a little bit. Stack some 1x1x1 rigidbody cubes on top of each other, and you’ll see the same effect (each will be only about 0.99 higher.) This might be accounting for the 0.02 (0.5-0.48) change.
The setting (I think) is in Edit->Physics->MinPenetation. But feel like setting it to 0 just makes nearly resting objects shake too much.
The amount is consistent. You can usually not worry about it, but accounting for it in code seems to work.