# Stealth Tutorial - Camera Movement Help!

Okay, for a school project after finishing the Stealth tutorial, we are told to redesign the map to an appropriate standard. Now this is where my problem comes in. The camera will follow my player, but after going into a building or through some, the camera stays outside and follows my player. (Meaning that it will just stay there and eventually I’m controlling a microscopic version of Ethan in the distance. How would I fix this? I understand the code defines why it’s doing what it is doing, but I don’t have the knowledge or expertise to change it without ruining the camera. The code below is my current CameraMovement script. Is there a way in which I can make the camera constantly follow me regardless of the walls?

``````using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour
{
public float smooth = 1.5f;

private Transform player;
private Vector3 relCameraPos;
private float relCameraPosMag;
private Vector3 newPos;

void Awake ()
{
player = GameObject.FindGameObjectWithTag(Tags.player).transform;

relCameraPos = transform.position - player.position;
relCameraPosMag = relCameraPos.magnitude - 0.5f;
}

void FixedUpdate ()
{
Vector3 standardPos = player.position + relCameraPos;

Vector3 abovePos = player.position + Vector3.up * relCameraPosMag;

Vector3[] checkPoints = new Vector3[5];

checkPoints[0] = standardPos;

checkPoints[1] = Vector3.Lerp(standardPos, abovePos, 0.25f);
checkPoints[2] = Vector3.Lerp(standardPos, abovePos, 0.5f);
checkPoints[3] = Vector3.Lerp(standardPos, abovePos, 0.75f);

checkPoints[4] = abovePos;

for(int i = 0; i < checkPoints.Length; i++)
{
if(ViewingPosCheck(checkPoints*))*
``````
• `````` 		break;*
``````
• `````` }*
``````

_ transform.position = Vector3.Lerp(transform.position, newPos, smooth * Time.deltaTime);_

• `````` SmoothLookAt();*
``````
• }*

• bool ViewingPosCheck (Vector3 checkPos)*

• {*

• `````` RaycastHit hit;*
``````
• `````` if(Physics.Raycast(checkPos, player.position - checkPos, out hit, relCameraPosMag))*
``````
• `````` 	if(hit.transform != player)*
``````
• `````` 		return false;*
``````
• `````` newPos = checkPos;*
``````
• `````` return true;*
``````
• }*

• void SmoothLookAt ()*

• {*

• `````` Vector3 relPlayerPosition = player.position - transform.position;*
``````
• `````` Quaternion lookAtRotation = Quaternion.LookRotation(relPlayerPosition, Vector3.up);*
``````

_ transform.rotation = Quaternion.Lerp(transform.rotation, lookAtRotation, smooth * Time.deltaTime);_

• }*
}

I just add the camera as child of my players and use near clip to chop buildings up, that being set with a triggerable plane.
Might I ask why you are using a raycast for something so seemingly simple?