Simple Follow Camera for Detective So-and-so

I wanted to have the option to do both third and first person view with a following camera as opposed to a fixed position. The control feels more than a little funny at the moment (some of that is due to the computer I’m on… it’s literally held together with duct tape). But the function seems to work well enough for now.

Here’s my camera follow script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour {

GameObject player;
GameObject camera;

[SerializeField] bool thirdPersonView = true;

//Camera POS 3rd Person
Vector3 cameraPos3rdPerson = new Vector3 (0,2.5f, -4);
Vector3 CameraRot3rdPerson = new Vector3(7,0,0);
//Camera pos 1st Person
Vector3 cameraPos1stPerson = new Vector3 (0, 1.4f, 0);
Vector3 CameraRot1stPerson = new Vector3(0,0,0);

// Use this for initialization
void Start () {
	player = GameObject.FindGameObjectWithTag("Player");
	camera = GameObject.FindGameObjectWithTag("MainCamera");
}

// Update is called once per frame
void LateUpdate () {
	SetCameraPosition();
	transform.position = player.transform.position;
	transform.rotation = player.transform.rotation;
}

void SetCameraPosition(){
	if (thirdPersonView) {
		camera.transform.localPosition = cameraPos3rdPerson;
		camera.transform.localEulerAngles = CameraRot3rdPerson;
	}else{
		camera.transform.localPosition = cameraPos1stPerson;
		camera.transform.localEulerAngles = CameraRot1stPerson;
	}
}

}

SO, while this seemed usable in the combat sandbox as soon as I set up a scene with place holders it’s problems became very apparent. I may try one of the stock cameras and where that takes me.

How would u change between third and first Person mode with button or MouseScrollwheel like zoomin amd and ZoomOut.Could u tell me abit more so maybe i could helpe u :slight_smile:

Privacy & Terms