Need help with my camera...

Up front, if this is in the wrong spot, I am sorry. Feel free to move this if you need to / can. I assumed “general” could accept this topic. Also, I am a beginner so thank you for bearing with me. If you feel a guide is out there that can help me with my needs (I’ve looked and can’t find quite the desired effect), then a simple link even would be appreciated. Of course, I’ll accept any help I can get. Thanks in advance.

I have a script attached to my camera which basically follows the player. I have slightly more code as well which is supposed to allow the player to rotate the camera upon request (arrow keys). Horizontally, this seems to work fine. However, when I enable the option the rotate horizontally to the player, all of a sudden, when the player moves (and not rotates the camera upon request) the camera rotates by itself. It makes no sense to me.

My desired result would be for the camera to follow the player, and the player could rotate the camera with his/her arrow keys. If the player doesn’t want the camera to rotate, it should NOT rotate (stay still, but still centered on the player). My best example would be Runescape’s camera system.

On a slightly different topic, I would also like to get the camera able to rotate along the PLAYERS x axis (to give the appearance of vertical rotation around the player) but I’ve only been able to achieve this around the worlds x axis, and not the perceived x axis of the player (assuming he/she already rotated the camera horizontally). Any additional ideas? Thanks.

Here’s the code I have attached the player (C#):

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {

public Transform target;
public float angularSpeed;

[SerializeField][HideInInspector]
private Vector3 initialOffset;

private Vector3 currentOffset;

[ContextMenu(“Set Current Offset”)]
private void SetCurrentOffset () {
if(target == null) {
return;
}

initialOffset = transform.position - target.position;
}

private void Start () {
if(target == null) {
Debug.LogError (“Assign a target for the camera in Unity’s inspector”);
}

currentOffset = initialOffset;
}

private void LateUpdate () {
transform.position = target.position + currentOffset;

float movementHorizontal = Input.GetAxis (“Horizontal”) * angularSpeed * Time.deltaTime;
float movementVertical = Input.GetAxis (“Vertical”) * angularSpeed * Time.deltaTime;
if(!Mathf.Approximately (movementHorizontal, 0f))
{
transform.RotateAround (target.position, Vector3.up, movementHorizontal);
currentOffset = transform.position - target.position;
}
if (!Mathf.Approximately (movementVertical, 0f)) {
transform.RotateAround (target.position, Vector3.right, movementVertical);
currentOffset = transform.position - target.position;
}
}
}

You are trying to rotate the camera right?

You attached the script to the player game object I presume? Your code is apparently written for attachment to the camera object.