- Home /
How do I use mouse look for my FPS?
I've looked around and cannot seem to find a simple how to on mouse look. I'm making a FPS and I would like to look around with the mouse. I have a FP Controller with mouse look C# attached with mouseX as axes. Then my main camera(which is a child of the FP controller) has mouse look C# attached with mouseY as the axes. Now when I play my game the camera does not follow the mouse. Can anyone help? The only tutorials I see are about writing my own mouse look script.
$$anonymous$$y First Person Controller is tagged as "Player" and $$anonymous$$ain Camera is tagged as "$$anonymous$$ainCamera".
Answer by SteelArrow21 · Apr 19, 2014 at 12:50 AM
If you imported all the packages, there should be a script that allows you to look around in FPS. When you test the game however, your cursor will go off screen while the FPS is still looking around. If you run a build, that would not be the case.
I have the $$anonymous$$ouseLook script and HideCursor script attached to my First Person Controller, and have followed the directions that are in the $$anonymous$$ouseLook script.
Answer by BeginnerPlzHelp · Nov 03, 2020 at 03:38 PM
So if you need any more help just ask me, I'm a beginner coder but i know some things so this is my Mouse Look script, it comes with a tutorial on what to do in unity as well,
UNITY TUTORIAL so in unity create an empty object > make it a parent of the main cam > give the empty object a character controller component > then apply a "cylinder" body to it to make it actually visible.
SCRIPT (make sure you apply this script to the main camera that is on the player, you don't wanna have it on the empty object)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MouseLook : MonoBehaviour {
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float MouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float MouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= MouseY;
xRotation = Mathf.Clamp(xRotation, -90, 90);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * MouseX);
}
}
From what I've heard, you need Unity 2019.4, also to look sideways doesn't work but looking up and down does (this is just what I'm experiencing)
Answer by RealEfrain12 · Dec 07, 2020 at 12:57 PM
@BeginnerPlzHelp yeah, well more specifically I’m talking about how this is working, also I know this code, it’s from Brackeys, and yes how do I know? It’s because I used the same exact code
Your answer
Follow this Question
Related Questions
Turret on Tank rotating fine until I'm not flat on ground 1 Answer
Top down shooter mouse look (3d) 2 Answers
How do i make camera movement smoother? 1 Answer
Editting standart charcontroller 0 Answers
C# Crosshair 4 Answers