Click and drag to rotate camera, like a pan?

Hello,

For an application I am trying to make a first person camera that rotates around it’s own axis to look around, so the camera stands still. To rotate the camera/view around the user would move the mouse somewhere on the screen, click and then drag to move the camera. Exactly the same way that Google Street View handles it.

link to street view example: Google Maps

I am new to coding more advanced languages involing vectors, quaternions and what not, and I understand that some of what needs to happen is to calculate distances and differences between the mouse starting position and moving position in relation to the camera, but I am having a difficulty wrapping my head around it all?

I have looked and looked for others trying to do the same very few came up, and none yielded any results.

Any help and or suggestions on where to find some information, would be much apprecieated.

This work for me

Just attatch on Camera

using UnityEngine;

public class StreetViewCamera:MonoBehaviour {
	public float speed = 3.5f;
	private float X;
	private float Y;

	void Update() {
		if(Input.GetMouseButton(0)) {
			transform.Rotate(new Vector3(Input.GetAxis("Mouse Y") * speed, -Input.GetAxis("Mouse X") * speed, 0));
			X = transform.rotation.eulerAngles.x;
			Y = transform.rotation.eulerAngles.y;
			transform.rotation = Quaternion.Euler(X, Y, 0);
		}
	}
}

You should check out the MouseLook script in the Standard Asset FirstPersonController. What you’re describing is virtually identical… you’d just need to check if the mouse button is down to activate it.

Camera.main.transform.Rotate(new Vector3(0, Input.GetAxis(“Mouse X”)*rotateSpeed, 0), Space.World);