I have 2D mesh in the XY plane. I have the following script which moves the camera across the plane, the camera starts at (0,0,-10). Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class DragMap : MonoBehaviour { private float dist; private Vector3 MouseStart; private Vector3 derp; void Start () { dist = transform.position.z; // Distance camera is above map } void Update () { if (Input.GetMouseButtonDown (2)) { MouseStart = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist); MouseStart = Camera.main.ScreenToWorldPoint (MouseStart); MouseStart.z = transform.position.z; } else if (Input.GetMouseButton (2)) { var MouseMove = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist); MouseMove = Camera.main.ScreenToWorldPoint (MouseMove); MouseMove.z = transform.position.z; transform.position = transform.position - (MouseMove - MouseStart); } } } But I cannot for the life of me figure out what to change so that if I drag my mouse to the right, the camera goes to the left and vice versa. Similarly if I drag my mouse up I want to move the camera down and vice versa. Help! Thank you for any replies. -DrOmega.
When you use '(MouseMove - MouseStart)' you create a delta vector that shows the difference between where you started and where the mouse is now. You can simply negate the contents of the x and y components to reverse how the camera moves. If you want to negate both you could change it to '(MouseStart - MouseMove)' instead.