Camera Movement, Help Please [Kind of a noob here]

Right, so I’m trying to make a camera movement system that is in third person and that allows you to pan the camera around your player (model, character, torso, whatever) while staying equidistant from the object and always looking at it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera_Rotation : MonoBehaviour
{

    // Use this for initialization
   
    public GameObject target;//the target object
    private float cam_speed = 10.0f;//a speed modifier
    private Vector3 point;//the coord to the point where the camera looks at

    void Start()
    {
        point = target.transform.position; //get target's coords

    }

    void Update()
    {
        while (Input.GetKey("Mouse 1"))
        {
            transform.LookAt(point);//makes the camera look to it

            if (Input.GetAxis("Mouse X") > 0)
            {
                transform.RotateAround(point, new Vector3(1.0f, 0.0f, 0.0f), 20 * Time.deltaTime * cam_speed);
            } else if (Input.GetAxis("Mouse X") < 0)
            {
                transform.RotateAround(point, new Vector3(-1.0f, 0.0f, 0.0f), 20 * Time.deltaTime * cam_speed);
            }


            if (Input.GetAxis("Mouse Y") > 0)
            {
                transform.RotateAround(point, new Vector3(0.0f, 0.0f, 1.0f), 20 * Time.deltaTime * cam_speed);
            }
            else if (Input.GetAxis("Mouse Y") < 0)
            {
                transform.RotateAround(point, new Vector3(0.0f, 0.0f, -1.0f), 20 * Time.deltaTime * cam_speed);
            }

        }
    }
}

This is my code. This script is located inside the actual camera and the target variable is set to the camera’s parent (the capsule shape called mainPlayerPart).

In case you are curious, the errors just say that “Mouse 1” is unknown even though I have seen mouse1 representing the secondary mouse button on unity’s list…

Anyway, my movement script is working fine, the game plays. However, when I enable the script (Camera_Rotation), here’s what happens:

Notice the Pause and Play button being both highlighted. This is what happens, the view stays the same and I am not put into game at all.

Can anyone help me finish this?

PS, the transformation things with target, etc, I got by using some of the forums because I could not for the life of me figure out how to move the camera a few pixels to the right ( turns out you can’t just do :

void Start() {

public var cam = Camera.main;
public GameObject target;
}

void Update() {
cam.lookAt(target);
cam.translate.position += (Vector3.left * Time.deltaTime, relativeTo = Space.self);

}

because, hell, that would just be so much easier and would make everything so much easier, so why do that…)

Anyway, can someone help me debug this and create a working camera, thanks.

Do you want to pan the camera, or orbit the camera around the player?
You have to be a bit more specific about what you are trying to achieve.

I guess I mean orbit, however I said Pan because I didn’t want movement to be limited just to the X axis (like a classic planetary orbit for example), I wanted the camera to be moved both axes. If you look at my code you will be able to see what I am trying to do.

Here is some pseudocode if you need clarification:

Start() {
target = mainPlayerObject
cam_speed = 2.0f
camera = Camera.main
}

Update(){

while (user holding down ("Mouse 1")){

if (axis ("Mouse X") > 0) {
camera.LookAt(target)
camera.position = Vector3.left*cam_speed, relative To = target
camera.LookAt(target)
} else if (axis ("Mouse X" < 0))
camera.LookAt(target)
camera.position = Vector3.right*cam_speed, relative To = target
camera.LookAt(target)
} 
//for the X axis movement

if (axis ("Mouse Y") > 0) {
camera.LookAt(target)
camera.position = Vector3.down*cam_speed, relative To = target
camera.LookAt(target)
} else if (axis ("Mouse Y" < 0))
camera.LookAt(target)
camera.position = Vector3.up*cam_speed, relative To = target
camera.LookAt(target)
} 
//for the Y axis movement

//I want to be able (while Im holding the secondary mouse button (RMB) down, to look around the player(have the camera orbit I guess) but in both axes at the same time, so it would allow the camera to move in pretty much any direction I guess...

}

Thanks for help in advance!

Ah thanks for the clarification.
You could set something like this up yourself (or with a tutorial), but your probably better off just using unity’s pre-built camera rig, which includes things like wall-clip avoidance and smoothed movement.

To get it just go to Assets > Import Package > Cameras In the top menu-bar,
Select everything then Import.

The one you want seems to be the FreeLook camera. Check the actual script’s comments if you want to know what anything does.

Good luck!