Les voitures ont un meilleur gps

Les voiture maintenant suivent des coordonnées fournies par un AStarGrid2D
au lieu de bétement faire une diagonale vers le prochain point du lapin
ce qui fait que, maintenant elle ne peuvent plus vraiment monter sur les
troitoirs car ils ne font pas partis du calque de navigation.
This commit is contained in:
Thomas
2025-02-25 11:37:45 +01:00
parent 8a6af2b01e
commit dcb63f7fe0
8 changed files with 80 additions and 47 deletions

View File

@@ -8,6 +8,7 @@ collision_mask = 3
script = ExtResource("1_bbbt2")
[node name="Label" type="Label" parent="."]
visible = false
offset_right = 40.0
offset_bottom = 23.0

View File

@@ -3,12 +3,14 @@ extends Node2D
@export var fullStop: bool = true
func _on_body_entered(body: Node2D) -> void:
$Label.text = str(body)+ " " + "body entered "
if OS.is_debug_build():
$Label.text = str(body)+ " " + "body entered "
if body.has_method("brake"):
(body as Car).brake(fullStop)
func _on_body_exited(body: Node2D) -> void:
$Label.text = str(body)+ " " + "body exited "
if OS.is_debug_build():
$Label.text = str(body)+ " " + "body exited "
if body.has_method("accelerate"):
(body as Car).accelerate()

View File

@@ -14,10 +14,11 @@ var fullStop = false;
var last_facing_direction = Vector2(0,-1) # facing north
var targetPosition = null
var targetGlobalPosition = null
var direction = Vector2(0,0)
func moveTo(position: Vector2) -> void:
targetPosition = position;
targetGlobalPosition = position;
func updateFacingDirectionInAnimationTree():
animation_tree.set("parameters/CarStates/driving/blend_position", last_facing_direction)
@@ -25,6 +26,8 @@ func updateFacingDirectionInAnimationTree():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
$ZIndexControler/ShapeCast2D.enabled = !$CollisionHorizontal.disabled
if brakePedal:
if fullStop:
current_speed = max(0, current_speed - acceleration)
@@ -32,12 +35,11 @@ func _process(delta: float) -> void:
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) * current_speed * delta
if (targetGlobalPosition != null):
direction = (targetGlobalPosition - global_position).normalized()
velocity = direction * current_speed
move_and_slide()
if velocity:
last_facing_direction = velocity.normalized()

View File

@@ -6,4 +6,8 @@
position = Vector2(-411, 81)
rotates = false
script = ExtResource("1_fbnn2")
speed = 1.0
[node name="Label" type="Label" parent="."]
visible = false
offset_right = 40.0
offset_bottom = 23.0