- Home /
How to Get My Camera to Follow First Person POV in First Person Controller
Hello!
I am using the default first person controller on Unity. My character is inside a house, and I want the player to move around inside the house. While trying out this level, I noticed that I have to switch what keypads I use depending on where I am in the room. Is there a way to make it so that I am always facing the direction that my person is going in (if I need to go backwards, the camera switches to that direction/ the camera follows the characters movement) so it doesn't feel weird when I move? My guess is that I would have to put in an if statement, but I am new to Unity and this type of coding. If I end up having to get rid of the MouseLook script, that's fine.
The scripts that I am using are the default MouseLook scripts that are attached to the First Person Controller. The script is below.
[AddComponentMenu("Camera-Control/Mouse Look")] public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
}
Thank you in advance for your help! And I'm sure someone else might have asked this question, but I can't find an answer so if you know where it might be, a link to the answer would be fine too!
Answer by andyspeak · May 05, 2014 at 12:39 PM
i dont realy get what you want like if you want a solid cam just add it to the character gameobject the u dont need any code
Your answer
![](https://koobas.hobune.stream/wayback/20220613144259im_/https://answers.unity.com/themes/thub/images/avi.jpg)