Hello, I am a noob at coding in c# and after a day of trying to create my own FPS camera looking script, I finally came up with a script that doesn’t give any errors… but it doesn’t work either.
When I run my game, the camera appears to be rotating a tiny bit when I move my mouse but it quickly returns back to zero, giving a sort of jittery effect.
Here is the code I’m trying to run:
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
public class PlayerLook : MonoBehaviour
{
float mouseSensitivity = 10f;
public Transform PlayerBody;
public Transform Cam;
// 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;
mouseX = Mathf.Clamp(mouseX, -90f, 90f);
PlayerBody.transform.localEulerAngles = new Vector3(0, mouseY, 0);
Cam.transform.localEulerAngles = new Vector3(-mouseX, mouseY, 0);
How to understand compiler and other errors and even fix them yourself:
For camera stuff you may wish to consider installing Cinemachine and using their stuff.
If you want to debug the above, to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
is this code even running? which parts are running? how often does it run?
what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.