Weird numbers in height from ground

I’m trying to get the exact height from the ground of a simple game object (sphere, cylinder, etc).

I have a floor of size 1 that is at y position -0.5. My understanding is that the center point of this floor is at y=-0.5, and since it is size 1, the top of it should be at y coordinate 0 exactly.

I have a sphere of size 1 with a rigidbody. It sits on the floor due to gravity. My understanding is it’s y position should be 0.5 when it is at rest on the floor, but it is 0.4800001 for some reason.

Similarly strange, I have a sphere of size 0.5. Based on the size 1 sphere’s weird y position, I would assume a sphere half the size would sit at y position 0.24000005 (half the size 1 sphere’s position). But instead, it sits on the floor at y position 0.2300001.

A cylinder behaves oddly as well. A size 1 cylinder sits at y position 0.98.

I need to be able to calculate what the y position of these objects will be on the floor so I can treat that position as zero. I can’t seem to calculate this number from the localScale, the collider.bounds or anything. Please correct my assumptions if they are wrong and tell me how to get the exact distance between the bottom of the objects and the top of the floor.

Look into the physics settings, particularly MinPenetrationForPenalty.

–Eric

Thanks Eric5h5, however the documentation says the default MinPenetrationForPenalty value is 0.05. Adding that to any of those y positions still doesn’t give the expected outcome. For example, the size 1 sphere sitting at 0.4800001 + 0.05 doesn’t equal the expected 0.5. Nor does adding it to the 0.2300001 y position of the size 0.5 sphere give me 0.25. I need a consistent way to calculate the distance from the edge of the object to the floor. Something like transform.position.y - (transform.localScale) * 0.5 + mysteryValue = 0;

Can you Raycast from the object to the floor to get the distance? I’m not sure if that would give you a more accurate distance, but its worth a try. Lowering MinPenetrationFor Penalty would probably give you more accurate numbers, but I don’t know how low you could go before causing issues with Physics. What level of accuracy do you need, and why?

@Zaladur The raycast gives me the same number as the y coordinate, as it is measuring from the center of the object. I just don’t understand why an object with the size of 1 sits at 0.48. I am trying to render sprites based on where the 3D shapes are. I am using the x and z of the object to position the sprite at x z, and I need to add it’s height from the ground to the sprite’s z coordinate to simulate height. But the objects are not sitting consistently on the ground because of this issue. I can get it “sort of ok” by fudging with some numbers, but I would prefer it to work with any size or shape I throw at it. For spheres it seems to be off by ~0.02 and for the cylinder it seems the not to use the center point at all (or maybe cylinder’s are twice as tall as they claim to be).