- Home /
What is the advantage of using Box Collider with a center of (0.5, 0.5, 0.5)
Hi, so I've recently taking some unity project from a another person that quit before. So, he setup all the object with box collider with a center (0.5, 0.5, 0.5) and put the object model as child wtih a transform position (0.5, 0.5, 0.5) so the collider is fitting the object model. But why doesn't he just left the center of box collider as (0, 0, 0) and the child model also as (0, 0, 0) for the position?
Is there some kind of advantage by doing that? Thanks in advance
Answer by Bunny83 · Apr 21 at 12:50 PM
This is usually done fo provide better scaling support. If the objects pivot is in the center, scaling the object means you always scale around the objects pivot. When adding the object as a child to another gameobject you can effectively shift the pivot. So scaling that parent would now scale around the parents pivot instead of the objects pivot.
As an example the Unity default cube mesh has the pivot in the center and has a side length of 1.0. So the vertices go from -0.5 to 0.5 on each axis. Scaling that cube up by a factor of 4 would make it grow around the pivot in all directions so it stretches from -2 to 2. When you offset the mesh inside a parent so the parent pivot sits at the corner of the default cube, scaling it up by 4 would keep the corner where the new pivot is located stay at the same point and make the object stretch away from that pivot.
Though this is just an assumption based on what you have said. We don't know what may be the reason behind this. Different games use different conventtions where the pivot / origin of an object is. Some games place the pivot of their models at the bottom which makes it easier to place them on the ground while others have it in the center. For example here's how valve employees talk about the object pivot / origin and how it usually is in the center, but not always.