- Edited
Hi, I'm working on my first 3D project. While following this tutorial for a 3D controller from GDQuest, I found some code to extend their camera controls to gamepad. I attached a script to the SpringArm for processing the camera input. I'm using _unhandled_input() to receive the input.
Here's the hierarchy for the nodes in question: Player |- SpringArm (Script in question) |- Camera
func _unhandled_input(event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
elif Input.is_action_just_pressed("basic"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if event is InputEventJoypadMotion:
print(event.axis_value)
yaw = fmod(yaw + (Input.get_action_strength("rs_left") - Input.get_action_strength("rs_right")) * gamepadSens, 360)
pitch = max(min(pitch + (Input.get_action_strength("rs_up") - Input.get_action_strength("rs_down")) * gamepadSens, 70), -50)
rotation_degrees = Vector3(pitch, yaw, 0)
elif event is InputEventMouseMotion:
rotation_degrees.x -= event.relative.y * mouseSens
rotation_degrees.x = clamp(rotation_degrees.x, -90.0, 30.0)
rotation_degrees.y -= event.relative.x * mouseSens
rotation_degrees.y = wrapf(rotation_degrees.y, 0.0, 360.0)
The trouble I've run into is while the mouse controls work perfectly well, it seems the gamepad motion is only received while the stick is in motion, not when stopped at any point. The intended behavior would be that if I hold left, for example, the camera would continuously move left and only stop once I release the stick.
Should I be using another method? I've tried using _input() but got the same results.