Files
chaussette.sale/vehicules/car.gd
Thomas 5721680834 Le z-indexeur est là pour z-indexer tous ces petits gars
Quand il rentre en action il trouve si quelqu'un est en collision
Et il prend la hauteur de cette personne et se place au dessus
Il est comme ça le zindexeur, il est sans gêne
2025-02-22 09:21:28 +01:00

32 lines
1.1 KiB
GDScript

class_name Car
extends CharacterBody2D
@export var debugLabel: Label
@export var speed = 750 # How fast the car will move (pixels/sec).
@onready var animation_tree := $AnimationTree
@onready var state_machine := animation_tree.get("parameters/driving/playback") as AnimationNodeStateMachinePlayback
var last_facing_direction = Vector2(0,-1) # facing north
var targetPosition = null
func moveTo(position: Vector2) -> void:
targetPosition = position;
func updateFacingDirectionInAnimationTree():
animation_tree.set("parameters/CarStates/driving/blend_position", last_facing_direction)
animation_tree.set("parameters/CarStates/idling/blend_position", last_facing_direction)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$ZIndexControler/ShapeCast2D.enabled = !$CollisionHorizontal.disabled
if (targetPosition != null):
velocity = (targetPosition - position) * speed * delta;
move_and_slide()
if velocity:
last_facing_direction = velocity.normalized()
updateFacingDirectionInAnimationTree()