dora/scenes/Player.gd

49 lines
1.0 KiB
GDScript
Raw Normal View History

2018-07-19 15:36:56 +02:00
extends KinematicBody
2018-07-19 15:36:51 +02:00
2018-07-19 15:37:10 +02:00
const norm_gravity = -100
2018-07-19 15:36:56 +02:00
var velocity = Vector3()
2018-07-19 15:37:08 +02:00
const MAX_SLOPE_ANGLE = 60
2018-11-07 13:57:10 +01:00
var has_reached_goal = false
2018-07-19 15:36:51 +02:00
func _ready():
2018-07-19 15:37:10 +02:00
pass
2018-07-19 15:36:51 +02:00
2018-07-19 15:36:56 +02:00
func _physics_process(delta):
2018-11-07 13:57:10 +01:00
if has_reached_goal:
return
2018-07-19 15:37:08 +02:00
# Keyboard input
2018-07-19 15:36:56 +02:00
var direction = Vector3()
2018-07-19 15:37:00 +02:00
if Input.is_action_pressed("ui_up"):
2018-07-19 15:37:04 +02:00
direction += Vector3(0, 0, -1)
2018-07-19 15:37:00 +02:00
if Input.is_action_pressed("ui_down"):
2018-07-19 15:37:04 +02:00
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()
2018-07-19 15:37:10 +02:00
# Speed
var speed = 3.0
2018-07-19 15:37:04 +02:00
direction *= speed
2018-07-19 15:37:08 +02:00
# Gravity
direction.y = norm_gravity * delta
# Collision
2018-07-19 15:37:10 +02:00
var floor_normal = Vector3(0, 1, 0)
velocity = move_and_slide(direction, floor_normal, 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
2018-07-19 15:36:56 +02:00
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass
2018-07-19 15:37:14 +02:00
func reach_goal():
2018-11-07 13:57:10 +01:00
has_reached_goal = true
print("Reached goal")