- Home /
Constructing a Vector in 2-space from an angle for camera panning
Hello all,
I am trying to pan an overhead camera around a map. To realize this goal, I am translating the camera's position based on the Mouse X and Mouse Y Input Axes and a "Pan Speed."
For moving right/left, I can simply use Vector3.Right and Space.Local, and all is well. However, since the Camera is tilted down, I cannot use Vector3.Forward and Space.Local, as that would have more of a "zooming" effect (I'd be getting closer/further to the ground, not panning).
I need to figure out the Vector by which I should translate, based on the Y-value from my Euler angles.
I thought this was a simple math problem, and used the formula U = cos(x), sin(x) to try to get the appropriate Unit Vector.
I tried to accomplish this via the following code snippet:
Vector3 forwardAngles = new Vector3(Mathf.Cos(transform.localEulerAngles.y * Mathf.Deg2Rad), 0, Mathf.Sin(transform.localEulerAngles.y * Mathf.Deg2Rad));
forwardAngles.Normalize();
transform.Translate(forwardAngles * Input.GetAxis("Mouse Y") * panSpeed * -1 , Space.World);
But somehow I am calculating the Vector incorrectly. Please advise.
Love Unity!
Answer by tigertrussell · Jun 14, 2013 at 12:14 AM
I ended up creating a parent game object which I could use Vector3.forward and Vector3.right on. This is a much easier solution.
Your answer
Follow this Question
Related Questions
Angle between two lines in 2D 3 Answers
Raycasting at an offset angle? 4 Answers
Find point on circle 1 Answer
Using "rigidbody.AddForce" to throw an object towards a target - iOS 1 Answer