- Home /
How to scale and translate world relative to camera
Unity Answers Question
At Unite 2012 there was a presentation by the people who made Universe Sandbox. The video can be found here: http://video.unity3d.com/video/6958259/unite-2012-creating-the At about 21:00 someone asks about how they achieve the scale and they answer but with limited detail.
Based on what they talked about, they provide the scale and positioning by leaving the camera in one location, and then scaling/translating the objects within the world (so moving everything in the world but leaving the camera at [0,0,0])
My questions are these: (a) how would I efficiently translate all the objects in a scene so it appears the camera is moving, but it is, in fact, staying in the same place. and (b) how would I scale and translate the objects in a scene (when I spin the scroll wheel, for example.) so that it looks like the camera is zooming out or into a point? ie what is the math involved. The guy in the video mentioned something like taking the distance to the nearest object and then using 1/(the distance) as the scale factor. But that left some holes like how much to translate by. (unless I simply misunderstood or missed some detail)
Thanks
Answer by The-IT664 · Apr 17, 2013 at 03:01 AM
Unfortunately I don't have the time to write up a more detailed answer but the general concept behind leaving the camera at the origin is to transform everything else by the inverse of what would have been the camera's transform. So, for example, if you were to place all your game objects on a parent "Base" and apply the inverse of whatever transformation you would have applied to the camera, then you get the effect you are after.
a) By placing all your GameObjects on a "Base" GameObject which you apply a inverse transformations to you won't get a performance penalty.
b) Scaling and rotating objects in the scene would work in the same way as translating them. Apply an inverse rotation/scale to the Base.
Also, note that they make have used this system to get around floating point precision limitations. Make sure you fully understand the issues and limitations of floating point numbers if you plan on making a very large scale scene.
All the best!
Edit: I should mention I don't have the time or speakers to view the video. Edit2: Zooming in and out can be faked using position and scale but more correctly it is a function of the camera's field of view.
Your answer
Follow this Question
Related Questions
smooth motion 1 Answer
Moving the grabbed objects changes their scale 0 Answers
Move object forward 1 unit then stop 2 Answers
Setting pivot to the middle of two touches - 2D project 0 Answers
How to stop coroutines or functions 2 Answers