- Home /
Where is the transform.position inside of a GameObject?
I'm new to unity and game development but I've been thinking about this problem. I don't know where the transform.position of a gameobject really is and the documentation kind of skips that detail. If I create a new cube, is the transform.position smack dab in the center or the object or is it in the center at the bottom or something else completely?
Isn't knowing the position of the transform essential to finding the sides of the mesh? For example, the x of the right side of a cube would always be transform.position.x + 5 in a 10x10x10 cube if the transform.position is exactly in the center. But, it's transform.position.x + 10 if the transform is in the upper left corner so I feel like knowing the transform.position is really important.
How else can I attach prefabs together? I want to build walls without gaps between them.
for default shapes I think its always exact centre, but if you make it the child of a parent somewhere else you could use the parents position, not that that would really help ;) you can do the maths very easily for a cube anyway to make them have no gaps inbetween
Btw: Unity supports vertex-snapping in the editor. Just hold down "v". You will be able to grab the object at the nearest vertex. It will automatically snap to any other vertex around.
You can also grab the object at the center handle and after that press "v". now you can use the objects pivot to snap it to another vertex.
I didn't know that @Bunny83 that will be useful for me thanks :)
Answer by Eric5h5 · Aug 18, 2011 at 10:11 PM
The transform.position is wherever the pivot point of the mesh is.
Yah -- it's really a modelling question. A gun made in 3DS max or Blender might have transform.position at the trigger (makes it easier to put in char's hand) or might have it dead-center to make it easier to spin in the weapon select box, or back-center for easier wall-mounting... . A spear could have transform.position at the butt, middle or tip.
Your answer
Follow this Question
Related Questions
transform.position not executed with OnTrigger2D 1 Answer
transform.position.x brings up error 1 Answer
Move gameObject with mouse 1 Answer
Attaching Object to mouse 1 Answer
How to determine speed of an object when using transform.position 2 Answers