How do i change this code to support joysticks???

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

onready var Yaw = get_parent()


func _ready():

func look_updown_rotation(rotation = 0):
var toReturn = self.get_rotation() + Vector3(rotation, 0, 0)
toReturn.x = clamp(toReturn.x, PI / -2, PI / 2)
return toReturn

func look_leftright_rotation(rotation = 0):
return Yaw.get_rotation() + Vector3(0, rotation, 0)

func mouse(event):
Yaw.set_rotation(look_leftright_rotation(event.relative.x / -CAMERA_TURN_SPEED))
self.set_rotation(look_updown_rotation(event.relative.y / -CAMERA_TURN_SPEED))

func _input(event):
if event is InputEventMouseMotion:
return mouse(event)

:bust_in_silhouette: Reply From: Wakatta

Change InputEventMouseMotion to InputEventJoypadMotion
Change event.relative.x and event.relative.y to axis_value
Change JOY_AXIS_0 and JOY_AXIS_1 to the ones you want to use

func mouse(event):
    if event.axis == JOY_AXIS_0:
        Yaw.setrotation(lookleftrightrotation(axis_value / -CAMERATURNSPEED))
    if event.axis == JOY_AXIS_1:
        self.setrotation(lookupdownrotation(axis_value / -CAMERATURNSPEED))

func _input(event):
    if event is InputEventJoypadMotion:
        return mouse(event)
if event.axis == JOY_AXIS_2:
	Yaw.set_rotation(look_leftright_rotation(axis_value / -CAMERA_TURN_SPEED))
if event.axis == JOY_AXIS_3:
	self.set_rotation(look_leftright_rotation(axis_value / -CAMERA_TURN_SPEED))

it just spins round weirdlt fast even without touching the sticks

James122333 | 2020-11-23 17:57