Whenever I start a new first person project, I use this video for both the player movement, and camera control.
It worked every time before, but now for some reason it doesn’t. First problem I encountered, was that the camera couldn’t move left or right, just up and down. I changed something (can’t remember what), and now it’s only moving diagonally, from bottom left to top right, and back.
Here’s the code I wrote down (as there’s no way of copy/pasting the code from the video).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camMouseLook : MonoBehaviour {
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
GameObject character;
void Start () {
character = this.transform.parent.gameObject;
}
void Update () {
var md = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
md = Vector2.Scale (md, new Vector2 (sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
mouseLook.y = Mathf.Clamp (mouseLook.y, -90f, 90f);
transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis (mouseLook.y, character.transform.up);
}
}
I’ve looked over it 5 times by now, and I still can’t find anything that I messed up while writing the code down. My guess is that there is a very tiny mistake I made that I for some reason can’t spot, or that the recent updates changed the unity API in some way.
I also have everything set up the same way the person in the video does (all scripts connected to the right objects, and the same components added to the right objects).