godot first person controller code example
Example 1: godot first person controller script
extends KinematicBody
onready var camera = $Pivot/Camera
var gravity = -30
var max_speed = 8
var mouse_sensitivity = 0.002
var velocity = Vector3()
func get_input():
var input_dir = Vector3()
if Input.is_action_pressed("move_forward"):
input_dir += -camera.global_transform.basis.z
if Input.is_action_pressed("move_back"):
input_dir += camera.global_transform.basis.z
if Input.is_action_pressed("strafe_left"):
input_dir += -camera.global_transform.basis.x
if Input.is_action_pressed("strafe_right"):
input_dir += camera.global_transform.basis.x
input_dir = input_dir.normalized()
return input_dir
Example 2: first person movement script for godot
godot movement script