extends KinematicBody
const MINCAMERAANGLE = -60
const MAXCAMERAANGLE = 70
export var camera_sensitivity: float = 0.05
export var speed: float = 10
var velocity: Vector3 = Vector3.ZERO
onready var head: Spatial = $Head
func ready():
Input.setmousemode(Input.MOUSEMODE_CAPTURED)
func physicsprocess(delta):
var movement = _getmovement_direction()
velocity = movement * speed
velocity = move_and_slide(velocity)
func unhandledinput(event):
if event is InputEventMouseMotion:
handlecamera_rotation(event)
func handlecamerarotation(event):
rotatey(deg2rad(event.relative.x * camerasensitivity))
head.rotatex(deg2rad(-event.relative.y * camerasensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(MINCAMERAANGLE), deg2rad(MAXCAMERA_ANGLE))
func getmovement_direction():
var direction = Vector3.DOWN
if Input.is_action_pressed("forward"):
direction -= transform.basis.z
if Input.is_action_pressed("backwards"):
direction += transform.basis.z
if Input.is_action_pressed("left"):
direction -= transform.basis.x
if Input.is_action_pressed("right"):
direction += transform.basis.x
return direction