- Home /
Question by
ham · Jan 11, 2013 at 07:05 PM ·
boxcollidercenter
finding the center of a 2d box collider,
hi i wanna instantiate an object excactly in center of a box collider but i dont know what should write in the position part of the instantiate function that is a vector3 instantiate(prefab , position , rotation) thanx for help,
Comment
Answer by jogo13 · Jan 11, 2013 at 11:11 PM
Apply the Box Collider's center xyz offsets to the gameObject's position:
Vector3 g_position = gameObject.transform.position;
BoxCollider box = GetComponent("BoxCollider");
Vector3 box_center = g_position + box.center;
Your answer
Follow this Question
Related Questions
Boxcollider Center Resetting to Zero Whenever Edited 0 Answers
OnTriggerEnter() incorrectly firing? 1 Answer
How do I know if a cube is lying flat on the ground? (the quickest way) 0 Answers
Move sprite depending on its collider position 1 Answer
Check if the center of an object is inside a trigger Collider? 1 Answer