Des feux rouges!

Pour arrêter les voiture vroom vroom
This commit is contained in:
Thomas
2025-02-24 18:09:33 +01:00
parent 3ba18fbddf
commit 725584c477
14 changed files with 427 additions and 15 deletions

View File

@@ -3,9 +3,15 @@ extends CharacterBody2D
@export var debugLabel: Label
@export var speed = 750 # How fast the car will move (pixels/sec).
@export var acceleration = speed / 100
@export var slowZoneSpeed = 300
var current_speed = speed;
@onready var animation_tree := $AnimationTree
@onready var state_machine := animation_tree.get("parameters/driving/playback") as AnimationNodeStateMachinePlayback
var brakePedal = false;
var fullStop = false;
var last_facing_direction = Vector2(0,-1) # facing north
var targetPosition = null
@@ -19,13 +25,26 @@ func updateFacingDirectionInAnimationTree():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if brakePedal:
if fullStop:
current_speed = max(0, current_speed - acceleration)
else:
current_speed = max(slowZoneSpeed, current_speed - acceleration)
else:
current_speed = min(current_speed + acceleration, speed)
$ZIndexControler/ShapeCast2D.enabled = !$CollisionHorizontal.disabled
if (targetPosition != null):
velocity = (targetPosition - position) * speed * delta;
velocity = (targetPosition - position) * current_speed * delta;
move_and_slide()
if velocity:
last_facing_direction = velocity.normalized()
updateFacingDirectionInAnimationTree()
func brake(needsToStop : bool):
brakePedal = true;
fullStop = needsToStop;
func accelerate():
brakePedal = false;