I have a board on the world X,Z axis. I have a camera that can rotate to look downward or upward and rotate left to right using the world Y axis.
Here's the camera rotation code:
float angle = (mouseX_Current - mouseX_ActionStart) * camRotationSpeedMod;
Camera.main.transform.Rotate(0.0f, angle, 0.0f, Space.World);
angle = (mouseY_Current - mouseY_ActionStart) * camRotationSpeedMod;
Camera.main.transform.Rotate(angle, 0.0f, 0.0f, Space.Self);
Using mouse button down and a mouse position input(drag&Drop) I translate the camera in the world. It receive a 2D vector that contain the X and Y value of the mouse(drag&drop) operation. Here's the code of the method I use :
private void CameraOnPlaneTranslation(Vector2 myVector)
{
float cameraYPos = Camera.main.transform.position.y;
Camera.main.transform.Translate(new Vector3(myVector[0], 0.0f, myVector[1]));
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, cameraYPos, Camera.main.transform.position.z);
}
Problem : When my camera is not oriented directly toward the Z Axis(0.0f, Z, 0.0f) the translation vector I compute is incorrect. I need to change the Y value of the vector so the camera don't move on the world Y axis.
Thanks