Hi, I'm trying to find the average center of several gameObjects. Here's my script thus far:
Transform[] transforms = model.gameObject.GetComponentsInChildren<Transform>();
Vector3 center = new Vector3(0,0,0);
int childCount = 0;
foreach(Transform tfs in transforms) {
center+=tfs.position;
childCount++;
}
center /= childCount;
Vector3 velocity = Vector3.zero;
target.transform.position = Vector3.SmoothDamp(target.transform.position, center, ref velocity, smoothTime);
It all seems reasonable to me. However, target's transform ends up being far from what I can visually attest as to being the center. If there's only one gameObject as a child of "model", it should center on that gameObject only correct? It doesn't. Therefore, I've concluded that the logic behind this script is flawed somewhere.
If somebody could point out that flaw, I'd be grateful.
Thanks, Elliot Bonneville