Pathfinding jusqu'au bout

This commit is contained in:
Thomas
2025-03-29 18:04:14 +01:00
parent aacfcc8e28
commit 6e34635cdc

View File

@@ -8,6 +8,7 @@ var toFollow: Array[Vector2i]
@export var can_walk_on_roads = false
var destination:Vector2 = Vector2.INF
var target_global_position:Vector2 = Vector2.INF
var HumanLayer = 0
var car_layer = 1
@@ -43,12 +44,16 @@ func _ready() -> void:
func _process(delta: float) -> void:
if !controled:
return
if controled.wants_to_interact_with:
destination = Vector2.INF
if destination != Vector2.INF:
var my_global_position = controled.get_feet_global_position()
var target_global_position = destination
if target_global_position != destination:
target_global_position = destination
# make the wanted position on the track move ahead by a certain amount
#if toFollow == null or toFollow.is_empty():
# compute the new navigation points the car should follow
var points = astar_grid.get_id_path(
world.local_to_map(world.to_local(my_global_position)),
@@ -60,7 +65,7 @@ func _process(delta: float) -> void:
if $Label.visible:
$Label.text = (
"position "+str(world.local_to_map(world.to_local(my_global_position)))+" , "+str(my_global_position)+
"\ntarget position "+ str(world.local_to_map(world.to_local(target_global_position)))+" , "+str(target_global_position)+
"\ntarget position "+ str(world.local_to_map(world.to_local(destination)))+" , "+str(destination)+
"\npoint to follow "+str(toFollow)
)
@@ -71,5 +76,9 @@ func _process(delta: float) -> void:
if !toFollow.is_empty():
controled.moveFeetTo(world.to_global(world.map_to_local(toFollow.front())));
else:
controled.face(target_global_position)
var distance_to_goal = abs(destination - my_global_position)
if distance_to_goal>Vector2(3, 3):
controled.moveFeetTo(destination)
else:
destination = Vector2.INF
target_global_position = Vector2.INF