0 votes

Hi there. I've got a problem.
I'm attempting to fix this "glitch"/"twitching" of the camera when rotated by this script:

onready var Head = $Head
onready var Eyes = $Head/Camera

var camera_angle = 0
# var camera_fov = 90
var camera_min_y = -90
var camera_max_y = 90
var mouse_sensitivity = 0.5
var mouse_drag_x = 0.4
var mouse_drag_y = 0.6

func _input(event):
    if event is InputEventMouseMotion:
        var camera_movement_horizontal = -event.relative.x * mouse_sensitivity * mouse_drag_x
        Head.rotate_y(deg2rad(camera_movement_horizontal))

        var camera_movement_vertical = -event.relative.y * mouse_sensitivity * mouse_drag_y
        if camera_movement_vertical + camera_angle < camera_max_y and camera_movement_vertical + camera_angle > camera_min_y:
            Eyes.rotate_x(deg2rad(camera_movement_vertical))
            camera_angle += camera_movement_vertical
        else:
            Eyes.rotation_degrees.x = camera_max_y if camera_movement_vertical > 0 else camera_min_y

It works enough for a camera to rotate and respect its boundaries but if done quickly up and down it starts to snap at -90 and 90 degrees.

Is there a fix for that?

PS. The Godots FPS tutorial suffers the same snap effect if MOUSE_SENSITIVITY is sped up (like 0.3 or more).
PS. Code inspired by First Person Controller Tutorial by Jeremy Bullock
PS. Im still learning both the engine and the eng lang. O' right?

in Engine by (12 points)
edited by

1 Answer

0 votes

Maybe have a debounce system with a yield function or something like that. Idrk.

by (77 points)
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 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 webmaster@godotengine.org with your username.