dora/Player.gd

40 lines
873 B
GDScript

extends KinematicBody
const norm_gravity = -80
var velocity = Vector3()
const MAX_SLOPE_ANGLE = 60
func _ready():
print("player init")
func _physics_process(delta):
# Keyboard input
var direction = Vector3()
if Input.is_action_pressed("ui_up"):
direction += Vector3(0, 0, -1)
if Input.is_action_pressed("ui_down"):
direction += Vector3(0, 0, 1)
if Input.is_action_pressed("ui_left"):
direction += Vector3(-1, 0, 0)
if Input.is_action_pressed("ui_right"):
direction += Vector3(1, 0, 0)
direction.y = 0
direction = direction.normalized()
# Speep
var speed = 2.0
direction *= speed
# Gravity
direction.y = norm_gravity * delta
# Collision
velocity = move_and_slide(direction, Vector3(0,1,0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
func _process(delta):
# Called every frame. Delta is time since last frame.
# Update game logic here.
pass