Help with my FPS Rotation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Millard

I’m trying to make a simple fps controller and am working on rotation with the mouse. This is the code I have.

extends KinematicBody

const MOUSE_SENSETIVITY = .3
const MOUSE_SENSETIVITY_X = 1


func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)


func _input(event):
    if event is InputEventMouseMotion:
	    rotation_degrees.y -= event.relative.x * MOUSE_SENSETIVITY
	    $Camera.rotation_degrees.x -= event.relative.y * MOUSE_SENSETIVITY_X

The left and right rotation works fine, but together with the up and down rotation it’s a little wonky. I was sure it would be, because I’ve never seen anyone do both x and y fps rotation the same way. To be honest I don’t really know what I’m doing very well. :slight_smile:

Could someone show me a better way to do it? Also could someone help explain how the code I’ve got works? My understanding of it is that its taking the current mouse motion and subtracting it from the last mouse motion to get the degrees it needs to set the characters rotation of it, but I’m not positive thats correct.

Thanks. :slight_smile: