Files
escape/Scripts/Player.gd
T

27 lines
765 B
GDScript

extends CharacterBody3D
const WALK_SPEED = 5.0
const MOUSE_SENS = 0.002
var mouse_mode = 2
func _ready():
Input.set_mouse_mode(mouse_mode)
func _input(event):
if event is InputEventMouseMotion and mouse_mode == 2:
$Pivot.rotate_y(-event.relative.x*MOUSE_SENS)
$Pivot/Camera.rotate_x(-event.relative.y*MOUSE_SENS)
elif event.is_action_pressed("mode"):
mouse_mode = mouse_mode ^ 1
Input.set_mouse_mode(mouse_mode)
func _physics_process(delta):
if mouse_mode == 2:
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
var direction = ($Pivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
velocity.x = direction.x * WALK_SPEED
velocity.z = direction.z * WALK_SPEED
move_and_slide()