In a camera script, I want the camera to be able to rotate around the player on the y-axis. This works fine, but when I make the camera follow the player, it won’t be able to rotate because it’s constantly being set to a certain position. How can I make the camera follow the player, but still rotate around the player as well?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour {
public Transform target;
public Vector3 offset;
public float yawSpeed = 100f;
private float yawInput = 0f;
private bool mouseDown = false;
void LateUpdate()
{
//transform.position = target.position + offset;
transform.LookAt(target);
if (Input.GetMouseButtonDown(1))
{
mouseDown = true;
}
if(Input.GetMouseButtonUp(1))
{
mouseDown = false;
}
if (mouseDown)
{
yawInput = Input.GetAxis("Mouse X") * yawSpeed * Time.deltaTime;
transform.RotateAround(target.position, Vector3.up, yawInput);
target.gameObject.transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
print(target.gameObject.transform.rotation.y);
}
}
}
Thanks!