- Home /
Get object orientation
Hi there!
I'm here to ask if it's possible to store an object (camera) orientation into a variable, so I can later use it to "match" another object (another camera) with it?
The objective is to make a "smooth transition" when I advance to the next "slide" in the scene (I'm creating a presentation based on Prezi "Zoom In Presentation", but in 3D), knowing that the second set of objects is in a different direction than the first set...
Thank in advance!
JPB18
Answer by hathol · Jun 01, 2012 at 04:20 PM
Yepp. A camera (like any other gameobject in unity) has a transform property that stores position, orientation and scaling of the object. If you are only interested in the orientation, store transform.rotation (type Quaternion). You can also smoothly interpolate between the two orientations by using Quaternion.Slerp()
Further info: http://unity3d.com/support/documentation/ScriptReference/Transform.html http://unity3d.com/support/documentation/ScriptReference/Quaternion.html
Answer by Berenger · Jun 01, 2012 at 04:18 PM
I suggest you create an empty gameobject for each positions - orientation you will have. Set them up properly in the editor, declare an array of transform in your script and then you can access the information you need at any time.
If you still want to only store a rotation though, declare a quaternion and affect you're camera's rotation to it.
Answer by Wolfram · Jun 01, 2012 at 04:23 PM
The best approach would be to create an empty GameObject for every pos/rot/scale setting you want to store. The additional advantage is, you could create/place them beforehand in your scene, and modify them with the transform handles, or with Ctrl-Shift-F and "AlignViewToSelected" etc.
As there are no Copy methods for the whole transform, you'd have to store/load the values individually. For example, to store the values, you'd do something like:
Transform mainCamTrans=Camera.main.transform;
myTransfomStorage[x].position=mainCamTrans.position;
myTransfomStorage[x].rotation=mainCamTrans.rotation;
myTransfomStorage[x].localScale=mainCamTrans.localScale; // there is no reliable global scale, but it's irrelevant for Cameras anyway, only for objects
Note you'd need special treatment (i.e., a small script attached to that empty GameObject) for additional camera settings such as FoV, near/far clip, ...
Your answer
Follow this Question
Related Questions
Functions via camera rotations... 1 Answer
Sprinting camera movement? (C#) 1 Answer
Orbit 2D camera around circle but keep lookat towards z axis 1 Answer
Multiple Cars not working 1 Answer