- Home /
Object width in treadmill script
For a treadmill effect, I have an array of objects that I shuffle around. As the objects in back go off screen I move them to the front. The way I calculate where to place objects in front is as seen below. All these objects are simple boxes of varying sizes with box colliders. For some reason, 2 of the 10 objects that I loop thru have approx 5 unity meters of padding between them and subsequently stacked objects. The only difference I can tell between these 2 objects and the others is that these 2 are unity cubes and the others are meshes imported via fbx. Can anyone explain this mystery space? Something must be wrong frontObject.transform.position.z or frontObject.renderer.bounds.size.z values.
function Update () {
var frontObject: GameObject = slabs[slabs.length-1];
var backObject: GameObject = slabs[0];
if (!backObject.renderer.isVisible) {
backObject.transform.position.z = frontObject.transform.position.z - frontObject.renderer.bounds.size.z;
slabs.Add(slabs.Shift());
}
}
Never$$anonymous$$d, I am not a smart man. I didn't consider the fact that Z is referencing the center of the object. Dumb.
Your answer
Follow this Question
Related Questions
Get width and height of Image in Unity 4.6 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How do I get the literal width of a RectTransform? 6 Answers
[UNSOLVED] Get a GameObject width and height in pixels (JS) 3 Answers
Is it possible to get the width (in unity units) of a GameObject including all of its children? 1 Answer