Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | XPrexuu |
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?