- Home /
How to get center of an object
Hi,
I want to use an cube(lets call "A") to move other objects(cube or capsule). Other objects will be moved when the object "A" is forwarding closely to these objects. Thus, i want to get the distance between "A" and other objects. So, i want to know the center coordination of an object? Thanks.
Answer by bblhaugh · May 30, 2013 at 10:21 AM
If your models aren't centered. transform.renderer.bounds.center
Brilliant general solution, would up-vote but not enough karma :P
Thanks. In 2017 this code is gone, ins$$anonymous$$d you can use
GetComponent< Renderer>().bounds.center
Renderer can no longer be found in Transform. GetComponent<> has to be used, as pointed out above!
Answer by Eric5h5 · Dec 10, 2012 at 02:09 AM
transform.position. The only way that wouldn't be the center is if you use off-center models that were not modeled around the origin.
It's perfectly valid not have model without the origin in center, e.g. a swing door with the origin on the rotation axis.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085215im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Error with picking up an item... 1 Answer
Unity 3d C# GUI box goes off to the side needs to be in the center of the screen 0 Answers
center of object group 0 Answers
C# Physics.SphereCast Center of Screen 2 Answers