Godot 4 FPS with Game Controller Support
Posted: Wed Jul 19, 2023 1:08 pm
So I thought I'd post up my FPS Controller Tutorial. I also noticed a problem with the code from the YouTube. I had forgotten to limit camera movement. So at the end of the code just add the following line...
The code should be like this.
Link to Tutorial....
Code: Select all
$Camera3D.rotation.x = clamp($Camera3D.rotation.x, deg_to_rad(-75), deg_to_rad(75))
Code: Select all
func apply_controller_rotation():
if (keyb):
var axis_vector = Vector2.ZERO
axis_vector.x = Input.get_action_strength("look_right") - Input.get_action_strength("look_left")
axis_vector.y = Input.get_action_strength("look_down") - Input.get_action_strength("look_up")
axis_vector = axis_vector.normalized()
if axis_vector.length():
if InputEventJoypadMotion:
rotate_y(deg_to_rad(-axis_vector.x) * controller_sensitivity)
$Camera3D.rotate_x(deg_to_rad(-axis_vector.y) * controller_sensitivity)
$Camera3D.rotation.x = clamp($Camera3D.rotation.x, deg_to_rad(-75), deg_to_rad(75))
Link to Tutorial....