- Home /
Positioning a GameObject relative to its bottom
When I set a position to a GameObject
it's done to its center.
Which is the best way to position a GameObject
relative to it's bottom. Is there a way to change its anchor point like in cocos2d-iphone
?
Answer by irgendeine · Apr 20, 2012 at 03:39 PM
You could calculate the actual height and width of objects with the help of their mesh and then add this to your center point to get the bottom:
MeshFilter mf = yourgameobject.GetComponent<MeshFilter>();
Vector3 objSize = mf.sharedMesh.bounds.size;
Vector3 objScale = yourgameobject.transform.localScale;
float objHeight = objSize.y * objScale.y (*anyparentobject.transform.localScale.y);
float objWidth = objSize.x * objScale.x (*parent.transform.localScale.x);
I hope I could avoid adding that logic. Thanks!,I was hoping to find a way to change the anchor point and avoid this logic. Thanks!
Unfortunately Unity 3.5 doesn't support changing anchor point, at least not via UI.
Your answer
Follow this Question
Related Questions
Place gameobject on ROI 0 Answers
Scale (Transform.localscale) a gameobject based on ARFaceAnchor anchorData 0 Answers
moving an object along a surface, then rotating it around end of surface 1 Answer
How to implement a system for "Road-Construction"? 1 Answer
Timeline animations and positioning game objects relative to other objects 1 Answer