I'm using something like the following to turn my camera in a Third-Person view (the script the following code is in is attached to a CameraGimbal node, which has an "InnerGimbal" child node, which then contains the camera. The script will orbit the camera around the player (which you will obviously have to fix in a first person view), but it demonstrates how you can access the gamepad's different analog axes.
func _ready():
camera = get_node("InnerGimbal/Camera")
func _process(delta):
if Input.get_connected_joypads().size() == 0:
return
var xAxis = Input.get_joy_axis(0, JOY_AXIS_2)
if abs(xAxis) > JOY_DEADZONE:
if xAxis >0:
xAxis = (xAxis-JOY_DEADZONE) * JOY_AXIS_RESCALE
else:
xAxis = (xAxis+JOY_DEADZONE) * JOY_AXIS_RESCALE
rotate_object_local(Vector3.UP, -xAxis * delta * JOY_ROTATION_MULTIPLIER)
var yAxis = Input.get_joy_axis(0, JOY_AXIS_3)
if abs(yAxis) > JOY_DEADZONE:
if yAxis >0:
yAxis = (yAxis-JOY_DEADZONE) * JOY_AXIS_RESCALE
else:
yAxis = (yAxis+JOY_DEADZONE) * JOY_AXIS_RESCALE
$InnerGimbal.rotate_object_local(Vector3.RIGHT, -yAxis * delta * JOY_ROTATION_MULTIPLIER/2)
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -1.0, 1.0)
emit_signal("camera_moved", camera)
Note the constants in caps - I have these defined like so, but in a real game the user would need to be able to configure these manually (also, a real game should give the player the opportunity to redefine the axis - I just use a hard-coded JOYAXIS2 because I'm still in dev mode).
const JOY_DEADZONE = 0.2
const JOY_AXIS_RESCALE = 1.0/(1.0-JOY_DEADZONE)
const JOY_ROTATION_MULTIPLIER = 200.0 * PI / 180.0