Pathfinding jusqu'au bout
This commit is contained in:
@@ -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,24 +44,28 @@ 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
|
||||
|
||||
# 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)),
|
||||
world.local_to_map(world.to_local(target_global_position))
|
||||
).slice(1)
|
||||
if !points.is_empty():
|
||||
toFollow = points
|
||||
if target_global_position != destination:
|
||||
target_global_position = destination
|
||||
|
||||
# make the wanted position on the track move ahead by a certain amount
|
||||
|
||||
# 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)),
|
||||
world.local_to_map(world.to_local(target_global_position))
|
||||
).slice(1)
|
||||
if !points.is_empty():
|
||||
toFollow = points
|
||||
|
||||
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)
|
||||
destination = Vector2.INF
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user