Hey guys! So I have the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CameraController : MonoBehaviour {
public Transform target;
public Vector3 offset;
public float zoomSpeed = 5f;
public float minZoom = 7f;
public float maxZoom = 10f;
public float pitch = 2f;
private float currentZoom = 10f;
private Vector3 newPosition;
void Start() {
transform.position = target.position - offset * currentZoom;
}
void Update() {
currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);
}
void LateUpdate() {
transform.LookAt(target.position + Vector3.up * pitch);
if(Input.GetKey("mouse 1")) {
transform.position += new Vector3 (Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"));
}
}
}
So, obviously, Iām trying to make the camera rotate around the ātargetā, however, Iām having problems with setting the new Z position:
...if(Input.GetKey("mouse 1")) {
transform.position += new Vector3 (Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"));
}...
At least, I think thatās the problem. Hereās a video of what happens when I test the script out:
As you can see, for some reason I canāt ROTATE around the player. I simply move the camera on one plane (as it seems).
However, when I go up and down with my mouse, it zooms in and out, instead of actually ROTATING around the player.
Can someone please help me? Iāve been stumped on this for a couple days now and I canāt seem, for the life of me, to get this right.
Also; I know I couldāve just searched online, but I have. Everything that comes up is scripts of other peopleās, and I donāt want the solution handed to me on a silver platter, I want to learn how I need to fix this, and whatās causing the issue, as Iām new to C#/Unity.
Thank you <3