Files
chaussette.sale/vehicules/car.gd
Thomas ec29c50631 Les voitures! Des carrosses à escence.
Et bien les voitures vois-tu, maintenant elles utilisent aussi
l'animation tree, le state machine of the future et les super autres
magiqueries.

Elles bougent grace à un Path2D qui est suivit par un PathFollow2D qui
leur sert de lapin. Elles suivent le lapin, sans cesse et sans cesse.
Elles sont sage.
2025-02-21 22:44:29 +01:00

28 lines
972 B
GDScript

class_name Car
extends CharacterBody2D
@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:
if (targetPosition != null):
velocity = (targetPosition - position) * speed * delta;
move_and_slide()
if velocity:
last_facing_direction = velocity.normalized()
updateFacingDirectionInAnimationTree()