#Joystick first person aiming stutters

4 messages · Page 1 of 1 (latest)

harsh viper
#

Hey, I am currently working on a game with a first person view and trying to have both mouse and keyboard as well as controller support working. Aiming with the mouse works great, but when I try to aim using the right joystick on a controller (I tried both an Xbox and a PS4 controller) the rotation of the view is stuttering.

I have a simple set up where I rotate the player's "head" based on the input.
Here is the code I have in the _input function that I use to detect whether i'm using a controller or a mouse.

func _input(event: InputEvent) -> void:
    if event is InputEventMouseMotion:
        rotate_y(deg_to_rad(event.relative.x * mouse_horizontal_look_sensitivity) * invert_horizontal_mouse_look)
        head.rotate_x(deg_to_rad(event.relative.y * mouse_vertical_look_sensitivity) * invert_vertical_mouse_look)

    if event is InputEventJoypadMotion:
        look_direction = Input.get_vector("look_left","look_right","look_up","look_down")
        rotate_y(deg_to_rad(look_direction.x * joypad_horizontal_look_sensitivity * invert_horizontal_joypad_look))
        head.rotate_x(deg_to_rad(look_direction.y  * joypad_vertical_look_sensitivity * invert_vertical_joypad_look))
    
    head.rotation.x = clamp(head.rotation.x,deg_to_rad(-89),deg_to_rad(89))

Also attached a video.

#

The only thing that comes to mind is that if I hold the right stick in a single direction it doesn't count as an input sometimes

harsh viper
#

So following that guide I updated the controller input code

look_direction = Input.get_vector("look_left","look_right","look_up","look_down",0.15).normalized()
    look_direction.x = look_direction.x * sqrt(1 - look_direction.y * look_direction.y / 2)
    look_direction.y = look_direction.y * sqrt(1 - look_direction.x * look_direction.x / 2)
    rotate_y(deg_to_rad(look_direction.x) * joypad_horizontal_look_sensitivity * invert_horizontal_joypad_look)
    head.rotate_x(deg_to_rad(look_direction.y)  * joypad_vertical_look_sensitivity * invert_vertical_joypad_look)