Files
chaussette.sale/caracters/player/player_controler.gd
Thomas 4da5046a5e Intérargir en marchant ne fait plus bugger
pas le temps d'expliquer, banzaï!
2025-03-06 09:26:45 +01:00

48 lines
1.5 KiB
GDScript

extends Node
@export var human: Human
@export var ray : ShapeCast2D
var interactable : Node2D
func _unhandled_input(event: InputEvent) -> void:
human.stop_interaction()
human.velocityVector = Vector2(0, 0)
human.wants_to_grab = false
human.wants_to_interact_with = null
if (
event.is_action("move_left") or
event.is_action("move_right") or
event.is_action("move_up") or
event.is_action("move_down")
):
human.velocityVector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
if event.is_action_pressed("grab"):
if interactable:
human.wants_to_interact_with = interactable
else:
human.wants_to_grab = true
func _process(delta) -> void:
ray.target_position = human.last_facing_direction * 48
if human.last_facing_direction.y > 0 :
ray.target_position = Vector2(0, 48)
(ray.shape as RectangleShape2D).size = Vector2(50, 20)
elif human.last_facing_direction.y < 0:
ray.target_position = Vector2(0, -48)
(ray.shape as RectangleShape2D).size = Vector2(50, 20)
elif human.last_facing_direction.x > 0 :
ray.target_position = Vector2(48, 0)
(ray.shape as RectangleShape2D).size = Vector2(20, 50)
else:
ray.target_position = Vector2(-48, 0)
(ray.shape as RectangleShape2D).size = Vector2(20, 50)
interactable = null
if ray.is_colliding():
var nbCollisions = ray.get_collision_count()
for n in range(nbCollisions):
var colider = ray.get_collider(n) as Node2D
if colider != null and colider != get_parent():
interactable = colider