Does anyone know of a tutorial that will help me make a grab and drag style camera? I want to be able to click and drag on the surface of the game world to move the camera around on the x-y axis (not up and down). I have written this script for the camera and it works, but it's really half assed since i don't really know how to make exactly what i want. P.S. The reason I am changing Y to Z is because Input.mousePosition returns Y as up and down and for some stupid reason transform.position uses Z as up and down. Why can't everything just use Z? Code (csharp): var HasClicked = false; var ClickedPosition = Vector3(0,0,0); function Start () { } function Update () { if (Input.GetMouseButton(0)) { if (HasClicked == false) { ClickedPosition = Input.mousePosition; HasClicked = true; } var NewVec = ClickedPosition - Input.mousePosition; NewVec.z = NewVec.y; NewVec.y = 20; transform.position = NewVec; } else { HasClicked = false; } } Thanks
I came accross a script that included some 3ds max like controls which included panning plus others. I have just done a quick search for it now but it's somewhere I can't remember so in the meantime you may find something on this page useful to your question. http://answers.unity3d.com/questions/26079/left-click-and-pan.html EDIT: You should be able to find it here http://wiki.unity3d.com/index.php/MouseOrbitZoom This is the bit I was talking about Code (csharp): // otherwise if middle mouse is selected, we pan by way of transforming the target in screenspace else if (Input.GetMouseButton(2)) { //grab the rotation of the camera so we can move in a psuedo local XY space target.rotation = transform.rotation; target.Translate(Vector3.right * -Input.GetAxis("Mouse X") * panSpeed); target.Translate(transform.up * -Input.GetAxis("Mouse Y") * panSpeed, Space.World); }