Files
chaussette.sale/caracters/player/player_controler.gd
Thomas bf4bfb9f5a faire le ménage dans le bouzin
abracadabrac!
2025-02-21 18:30:27 +01:00

37 lines
1.2 KiB
GDScript

class_name PlayerControler
extends CharacterBody2D
@export var speed = 450 # How fast the player will move (pixels/sec).
# intensions of the player turner into a boolean
@export var wants_to_grab = false;
@onready var animation_tree := $AnimationTree
@onready var state_machine := animation_tree.get("parameters/playback") as AnimationNodeStateMachinePlayback
var last_facing_direction = Vector2(0,-1) # facing south
func readInputs():
wants_to_grab = Input.is_action_pressed("grab");
if state_machine.get_current_node() == "grabing":
velocity = Vector2(0,0);
else:
velocity = Input.get_vector("move_left", "move_right", "move_up", "move_down") * speed
func updateFacingDirectionInAnimationTree():
animation_tree.set("parameters/walking/blend_position", last_facing_direction)
animation_tree.set("parameters/idling/blend_position", last_facing_direction)
animation_tree.set("parameters/grabing/blend_position", last_facing_direction)
func _physics_process(delta):
readInputs()
# move the caracter
move_and_slide()
# compute the direction the player wants to look at
if velocity:
last_facing_direction = velocity.normalized()
updateFacingDirectionInAnimationTree()