- Home /
Instantiate position tracking?
Hello. Suppose I repeatedly invoke a function that instantiates a random object. How can I use this to move the object(the one that is spawning the others) to the x.max bounding point of the newest object(and then, when the function is repeated, move to the next object, etc.)?
Answer by Joshua · Apr 29, 2011 at 02:41 PM
I have never used this, but looking at the docs you need to use this
After instantiating a new object you want to set your transform to it's x-max:
transform.position = Vector3(newObject.collider.bounds.extents.x,0,0);
The thing is though, your new instantiated object (which is random you said) will now be instantiated partly inside your previous object, because you compensated for the previous object's x-width, but not the new one's. So say first you used to instantiate at the position of the object you keep on moving to the right, now you want to instantiate at
newObject = Instantiate(object,Vector3(transform.position.x+object.collider.bounds.extents.x,transform.position.y ,transform.position.z)
If these objects have no collider, replace it with renderer.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130223im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
(GameObject).renderer.bounds.size.(axis) returns 0. 0 Answers
Shuriken won't render off camera bounds 0 Answers
render the bounding box of collider or mesh how to? 2 Answers
Antialiasing on iOS 1 Answer