- Home /
Move & Rotate Camera after OnMouseDown()
Hello,Everybody! HELP! I need advice! I Have camera which rotates around hexagon (i'm using MouseOrbit). The hexagon is separated on parts. Each part has a script. When I OnMouseDown() on one of these parts, I want the camera to move from it's position to position near this part and to look at it. here is image http://dl.dropbox.com/u/65491934/3.png
Answer by KruegerT · Mar 05, 2012 at 03:30 PM
I think you could get the local up vector of your clicked part, then modify this vector with the distance of the camera from your hexagon and then Lerp the camera to this position. In order that the camera look at this point you could use the LookAt-function and use the transform of the hexagon part, but i would prefer to let the camera always look at the center of your hexagon.
transform.LookAt(centerOfHexagon.transform)
Greetings, Thomas
Answer by Tjr · Mar 06, 2012 at 08:49 AM
Thanks for answer!Camera moves,but it's movement is really strange. I don't really understand what coordinates to use. Look,I have hexagon model,it is separated on parts(child objects with own transform). Center of hexagon is an empty object with own transform(child of hexagon model). What transform.positions i should use,and how make camera rotate relative to center??
http://unity3d.com/support/documentation/ScriptReference/Transform.RotateAround.html > use your emptyCenterObject.transform.position as "point" > this is world position (transform.localPosition is your relative position)