- Home /
First Person Player
Hello I'm creating a game with a First Person Player and am following Brackeys tutorial on First Person Movement: https://www.youtube.com/watch?v=_QajrabyTJc | but I doesn't work like Brackeys shows, instead it doesn't move when the mouse does and moves when holding the RMB it will move even without the code there. Here the code without Y movement using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseLook : MonoBehaviour { public float mouseSensitivity = 100f; public Transform playerBody; // Start is called before the first frame update void Start() { } // 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; playerBody.Rotate(Vector3.up * mouseX); } }
Thank anyone in advance
Answer by JasonBennett · Jan 07, 2020 at 05:13 PM
Hello,
There are a few things that could be going wrong. Let's try them in order:
1. Are you pressing "Play" to test? I only ask because the mouse does not typically control the camera with the RMB unless you are in the "Scene" view instead of the "Game" view.
2. Have you attached your MouseLook script to an object in the scene as a Component?
3. Have you attached the Player Object Transform to the MouseLook script (filling the field for the "playerBody" variable)?
One thing to try is to see your mouseX value by exposing a Debug Value field to the Unity Inspector. Declare the Debug variable up top and use public, then link it to the mouseX value in Update():
public class MouseLook: MonoBehavior {
public float DebugMouseX; //Delete me later
void Update()
{
float mouseX ...
DebugMouseX = mouseX;
This will allow you to debug its value by looking at the Component in your scene while you're in Game View, to make sure it is changing as expected. (You can accomplish the same thing via Debug.Log(mouseX), but it is a bit messier in the console.)
Let me know if none of those fixes work.
-Jason
Okay so, I was already doing the First 3 things correctly and the Debug value works however it displays as 0 at all times. I'm wondering if it has something to do with the Render Pipeline or because I'm running a newer version.
Huh, weird. Try Debug.Log(Input.GetAxis("$$anonymous$$ouse X");
to see if you're getting any input at all
Answer by The-Captain-Moo · Jan 09, 2020 at 03:46 AM
It is picking it up now and if giving me results other that zero but it is still not moving.
Could you post a screenshot of your inspector with the object highlighted that has the script on it?
Sorry I can't because I've deleted the files for it but thank you for your help.
Answer by calgraham545 · Apr 26, 2020 at 02:26 PM
Hi
I'm having this issues myself but there was no conclusion to this post
Im getting the error message
Assets/Assests to use/Utility/SimpleActivatorMenu.cs(11,16): error CS0619: 'GUIText' is obsolete: 'GUIText has been removed. Use UI.Text instead.'
This is my coding from Brackeys tutorial
Thanks
Cal
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
// Start is called before the first frame update
void Start()
{
}
// 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;
playerBody.Rotate(Vector3.up * mouseX);
}
}
Your answer
Follow this Question
Related Questions
Jittery FPS Camera when moving 3 Answers
How to restrict first person from turning 360 degrees when sitting? 1 Answer
Change standart FirstPersonController variables via other script 2 Answers
FPS Controller rotation,FPS Controller rotation problem 0 Answers
FPS controller and mouseLook problem 1 Answer