- Home /
Calculating an object's bounds...
Hello. I am trying to spawn an object in such a way so that the object that is spawned is edge to edge with the object that did the spawning. They both have box colliders attached to them but they are different lengths, I am trying to have them be right next to one another (just as if I had put them there manually). I created this script to do the job, but it is not working (the object is spawned at a seemingly random position).
Thanks.
var MyPrefab : GameObject;
function Update (){
transform.Translate(Vector3.right * Time.deltaTime * -1);
}
function OnTriggerExit (other : Collider) {
Instantiate (MyPrefab,Vector3(transform.position.x+collider.bounds.size.x+MyPrefab.collider.bounds.size.x, transform.position.y, transform.position.z), Quaternion.identity);
}
Answer by hathol · Jun 26, 2012 at 12:08 AM
Use bounds.extents instead of bounds.size. Since the object position is usually at the centre of the object, you should use only half of the size for each collider (extents is exactly that).
Your answer

Follow this Question
Related Questions
Can I use a raycast to retrieve information from the collider? 2 Answers
3d Text how do you autofit to a fixed space 0 Answers
collider bounds intersect but than for a UI button element 0 Answers
Problem with checking for intersection between two rotated objects 3 Answers
Collider2d.bounds.Intersects not detecting intersection 1 Answer