33 lines
877 B
GDScript3
Raw Normal View History

2024-02-07 22:04:19 +00:00
class_name PlayerController
extends Controller
## The character that we're controlling.
var player: Player
## We need the movement component to check if we can perform certain actions.
var movement: MovementComponent
func _init(new_player: Player):
player = new_player
movement = player.find_child("Movement")
func _unhandled_input(event):
if Global.interacting_with_ui:
return
# Calculate the direction
var move := Input.get_vector("move_left", "move_right", "move_forward", "move_backward")
2024-02-09 23:10:51 +00:00
var direction := (Global.camera.global_basis * Vector3(move.x, 0, move.y))
2024-02-07 22:04:19 +00:00
direction.y = 0
direction = direction.normalized()
# Notify components
player.set_direction(direction)
if event.is_action_pressed("jump") && movement && movement.can_jump():
player.jump()
2024-02-13 20:04:35 +00:00
for i in range(4):
if event.is_action_pressed("skill_%d" % (i + 1)):
player.use_skill(i)