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.

