35 lines
912 B
GDScript

class_name PlayerController
extends Controller
var player: Player
var movement: MovementComponent
var skills: SkillsComponent
func _init(new_player: Player):
player = new_player
movement = player.get_node("Movement")
skills = player.get_node("Skills")
name = "Controller"
func _unhandled_input(event: InputEvent):
if Global.interacting_with_ui:
return
update_direction()
update_actions(event)
func update_direction():
var move := Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
var direction := (Global.camera.global_basis * Vector3(move.x, 0, move.y))
direction.y = 0
direction = direction.normalized()
direction_changed.emit(direction)
func update_actions(event: InputEvent):
if event.is_action_pressed("jump") && movement && movement.can_jump():
jumped.emit()
for i in range(4):
if event.is_action_pressed("skill_%d" % (i + 1)):
used_skill.emit(i)