I have the following main camera script, which rotates as per the player’s rotations, i.e. player and camera both move in the same direction at the same time. The script is working fine, however, I am unable to change the position of the main camera. It is literally on the ground and I want to make it higher. Here is the script:
public class FollowPlayer : MonoBehaviour
{
[SerializeField]
float mouseSensitivity;
public Vector3 cameraOffset;
public Transform Player;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
cameraOffset = transform.position - Player.transform.position;
}
void Update()
{
Rotate();
}
private void Rotate()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
Player.Rotate(Vector3.up, mouseX);
}
private void LateUpdate()
{
transform.position = Player.transform.position + (-Player.transform.forward * cameraOffset.magnitude);
transform.LookAt(Player.transform);
}
}
I want the current functionality to persist, but I just want to position the main camera according to my own offset values, but this script is changing those values at run time.