You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

55 lines
1.2 KiB

extends KinematicBody
class_name Player
export var move_speed : float = 3.0
const norm_gravity = -150
var velocity = Vector3()
const MAX_SLOPE_ANGLE = 60
var has_reached_goal = false
func _ready():
pass
func _physics_process(delta):
if has_reached_goal:
return
# Keyboard input
var direction = Vector3()
if Input.is_action_pressed("ui_up"):
direction += Vector3(0, 0, -1)
set_rotation_degrees(Vector3(0, 180, 0))
if Input.is_action_pressed("ui_down"):
direction += Vector3(0, 0, 1)
set_rotation_degrees(Vector3(0, 0, 0))
if Input.is_action_pressed("ui_left"):
direction += Vector3(-1, 0, 0)
set_rotation_degrees(Vector3(0, -90, 0))
if Input.is_action_pressed("ui_right"):
direction += Vector3(1, 0, 0)
set_rotation_degrees(Vector3(0, 90, 0))
direction.y = 0
direction = direction.normalized()
# Speed
direction *= move_speed
# Gravity
direction.y = norm_gravity * delta
# Collision
var floor_normal = Vector3(0, 1, 0)
velocity = move_and_slide(direction, floor_normal, 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass
func reach_goal():
has_reached_goal = true
print("Reached goal")