First person controller for gamepad

Godot Version

4.2.2

Question

for some reason there is no tutorials on this.
i have this for now but it feels horrible do you have any other approaches?

    public override void _UnhandledInput(InputEvent @event)
    {
		if (@event is InputEventJoypadMotion joypadMotion)
		{
			head.RotateY(-Input.GetJoyAxis(0,JoyAxis.RightX) * (sens * 10)); 
			camera.RotateX(-Input.GetJoyAxis(0,JoyAxis.RightY) * (sens * 
                         10)); 

			camera.Rotation = new Vector3(
				Mathf.Clamp(camera.Rotation.X, Mathf.DegToRad(-60), 
                                 Mathf.DegToRad(60)),
				camera.Rotation.Y,
				camera.Rotation.Z
			);
		}
    }

you can use input map in project settings.

1 Like

In tandem with the input mapper the function, it may be better to register over-time events like movement and camera rotation in the _Process function. Instead using Input.GetVector("Left", "Right", "Down", "Up") to accumulate movement and rotation.

i have the movement down, i want to rotate the camera with the joystick.

See how it’s done in the third-person shooter demo:

This code could probably be simplified a bit in 4.0 onwards, but the gist is that you need to register four new actions (such as look_up, look_down, look_left, look_right) and bind them to the right stick on controller input. You then add to the camera rotation in _process() (not _input() or _physics_process()).

Mouselook input remains entirely separate (and in _input()) as it doesn’t emit those input actions.