- Home /
how to make camera to center the dynamically placed objects?
Hi guys......i am having number of cubes which are dynamically placed by a script and i want to show them in perfectly in center......means i can place cubes in a manner that they could be 3 by 3 or 4 by 4 or any other matrix.....so now what i want is that i have to show them perfectly in center so how could i do that??? any help will be much appreciated Thanks a lot in Advance.......if providing script then please use c#.......Thanks again.....
Answer by Fattie · Dec 17, 2012 at 11:40 AM
to find the center point of many items:
add them all up. and then divide by the number of items.
So if you have ten items it is ( A1 + A2 + A3 ... + A10 ) / 10.0
Note that the simplest example of this is: if you need the middle point between two things, it's (A+B)/2.0.
If you have all your items in an array: use a for loop to add them all up and then divide by the count. Unless we know exactly how you handle the items, it's hard to help you with that.
now you the the central position, CP, of all the items.
quite simply, use "LookAt" on your camera, with CP, to make the camera look at CP.
Hope it helps.
Does the / operator work on the Vector3 class? I'm just curious, I always divide each component (x,y and z) individually.
yes, that is exactly correct! it works fine.
you can say
0.20;
or you can say
/ 5.0;
Be sure to click here:
Contents/Documentation/Documentation/ScriptReference/Vector3.html
notice all the functions. Look at the BOTTO$$anonymous$$ of the blue functions.
It tels you everything about the different operators!
Your answer
Follow this Question
Related Questions
How to make your character move? 7 Answers
How to make camera position relative to a specific target. 1 Answer
MoveTowards problem 1 Answer
Switching Cameras at runtime 1 Answer