0 votes

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. :)

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. :-)

in Engine by (391 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.