Skip to content

Instantly share code, notes, and snippets.

@IAMACAR10
Last active March 3, 2025 04:28
Show Gist options
  • Select an option

  • Save IAMACAR10/e2506ab4fd505b6735431c68f0af1709 to your computer and use it in GitHub Desktop.

Select an option

Save IAMACAR10/e2506ab4fd505b6735431c68f0af1709 to your computer and use it in GitHub Desktop.
Godot First Person Character Controller
extends KinematicBody
onready var cam = $Camera
var speed = 5
var moveX = 0
var moveZ = 0
var gravity = 9.81
var sensitivity = 0.3
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
var mouse = event.relative
cam.rotation.x += -deg2rad(mouse.y * sensitivity)
cam.rotation.x = clamp(cam.rotation.x, deg2rad(-90), deg2rad(90))
rotation.y += -deg2rad(mouse.x * sensitivity)
func _process(delta):
if (Input.is_action_pressed("up")):
moveZ = -1
elif (Input.is_action_pressed("down")):
moveZ = 1
if (Input.is_action_pressed("left")):
moveX = -1
elif (Input.is_action_pressed("right")):
moveX = 1
func _physics_process(delta):
var move = Vector3(moveX, 0, moveZ) * speed * delta
translate(move)
moveX = 0
moveZ = 0
@IAMACAR10
Copy link
Author

kinda garbage, if anyone has advice on improving it then tell me. my movement system could definitely use some work, with proper physics like velocity, acceleration, etc.

@sunnyquebracodigos
Copy link

saved my life, ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment