Basically I want a click and drag camera but without teleporting the cursor to the center of the screen every time. What I have for camera movement so far is:
public class CameraController : MonoBehaviour
{
Vector3 camRot = new Vector3(0, 0, 0);
Vector3 camPosRot = new Vector3(0, 0, 0);
public float VSpeed = 2.0f;
public float HSpeed = 2.0f;
public Vector3 CameraOffset = new Vector3(0,0,0);
public Rigidbody Follow;
public float Distance = 0.1f;
Vector3 CursorBC;
Vector3 CameraPos = new Vector3(0, 0, 0);
// Start is called before the first frame update
void Start()
{
//Follow = GetComponent<Rigidbody>();
CameraPos = CameraOffset;
}
// Update is called once per frame
void Update()
{
camRot += new Vector3(-Input.GetAxis("Mouse Y") * VSpeed, Input.GetAxis("Mouse X") * HSpeed, 0);
if (Input.GetKey(KeyCode.Mouse1))
{
CursorBC = Input.mousePosition;
Cursor.lockState = CursorLockMode.Locked;
transform.eulerAngles = camRot;
camPosRot = new Vector3(camRot.y,camRot.x);
Vector3 RotationVector = new Vector3(Mathf.Sin(camPosRot.x * Mathf.Deg2Rad) * Mathf.Cos(camPosRot.y * Mathf.Deg2Rad), Mathf.Sin(camPosRot.y * Mathf.Deg2Rad), Mathf.Cos(camPosRot.x * Mathf.Deg2Rad) * Mathf.Cos(camPosRot.y * Mathf.Deg2Rad));
CameraPos = new Vector3(CameraOffset.magnitude * -(RotationVector.x), CameraOffset.magnitude * (RotationVector.y), CameraOffset.magnitude * -(RotationVector.z));
}
else
{
Cursor.lockState = CursorLockMode.None;
}
transform.position = (Follow.transform.position + CameraPos);
}
}
Only thing so far I've come across is to move it through .NET but that wouldn't really be multi-platform at all and also seems like a generally bad idea. Is my only option to make a "virtual mouse" as in a Vector3 position that I can control and wouldn't that not work with the GUI engine unity already has built in?