I can’t find a reference on this - how is the “world space” sphere collider radius determined based on the scaling aspect of the object (and its parents)?
I’d guess the “correct” approach would be to calculate the SVD of the local to world matrix, and take the maximum from the diagonal matrix. But that doesn’t seem to be happening, as the attached example shows - you can replicate it by (all in x,y,z order as in the editor, using a standard sphere primitive):
After some testing it seems like maybe the radius is just determined by taking the maximum of the lengths of the first 3 columns of the local to world matrix, but I’d appreciate a confirmation on this.
Without checking in detail, you’re probably right. It would be nice if the colliders also got distorted to match the uneven scale or skew that you have applied to the object, but I completely understand why they didn’t do that. It’s a LOT heavier computation to compute each possible intersection of primitives (ray vs sphere, sphere vs capsule, capsule vs box, etc.) if those primitives can be arbitrarily scaled with independent axes.
That’s not exactly what I meant - I don’t have an issue with the collider not being flattened, what I “mind” is that the mesh goes outside the sphere collider. I would expect the sphere’s radius would be adjusted in such a way, so that the mesh fits inside it, i.e. the sphere acting as a “bounding sphere”. But that’s not what happens.
I don’t really care what happens, this is fine too, but I’m working on an asset where I need to replicate the shape of the collider, so I would like to know how the radius is decided.
The “reasonable” method, of adjusting the sphere radius, so that the mesh fits inside it would be done using an SVD decomposition, and I’d know how to do that, but I don’t know how the radius is determined in Unity. Might just be maximum of length of columns of the local to world matrix like I mentioned, but I don’t know.
I’m not a 3D physics dev but here’s a pseudo-cope snippet from the SphereCollider native code. This is passed directly into the PhysX geometry (physx: PxSphereGeometry sSphere) radius: