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.