Pathfinding jusqu'au bout
This commit is contained in:
@@ -8,6 +8,7 @@ var toFollow: Array[Vector2i]
|
|||||||
@export var can_walk_on_roads = false
|
@export var can_walk_on_roads = false
|
||||||
|
|
||||||
var destination:Vector2 = Vector2.INF
|
var destination:Vector2 = Vector2.INF
|
||||||
|
var target_global_position:Vector2 = Vector2.INF
|
||||||
var HumanLayer = 0
|
var HumanLayer = 0
|
||||||
var car_layer = 1
|
var car_layer = 1
|
||||||
|
|
||||||
@@ -43,24 +44,28 @@ func _ready() -> void:
|
|||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
if !controled:
|
if !controled:
|
||||||
return
|
return
|
||||||
|
if controled.wants_to_interact_with:
|
||||||
|
destination = Vector2.INF
|
||||||
if destination != Vector2.INF:
|
if destination != Vector2.INF:
|
||||||
var my_global_position = controled.get_feet_global_position()
|
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
|
# 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
|
# compute the new navigation points the car should follow
|
||||||
var points = astar_grid.get_id_path(
|
var points = astar_grid.get_id_path(
|
||||||
world.local_to_map(world.to_local(my_global_position)),
|
world.local_to_map(world.to_local(my_global_position)),
|
||||||
world.local_to_map(world.to_local(target_global_position))
|
world.local_to_map(world.to_local(target_global_position))
|
||||||
).slice(1)
|
).slice(1)
|
||||||
if !points.is_empty():
|
if !points.is_empty():
|
||||||
toFollow = points
|
toFollow = points
|
||||||
|
|
||||||
if $Label.visible:
|
if $Label.visible:
|
||||||
$Label.text = (
|
$Label.text = (
|
||||||
"position "+str(world.local_to_map(world.to_local(my_global_position)))+" , "+str(my_global_position)+
|
"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)
|
"\npoint to follow "+str(toFollow)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,5 +76,9 @@ func _process(delta: float) -> void:
|
|||||||
if !toFollow.is_empty():
|
if !toFollow.is_empty():
|
||||||
controled.moveFeetTo(world.to_global(world.map_to_local(toFollow.front())));
|
controled.moveFeetTo(world.to_global(world.map_to_local(toFollow.front())));
|
||||||
else:
|
else:
|
||||||
controled.face(target_global_position)
|
var distance_to_goal = abs(destination - my_global_position)
|
||||||
destination = Vector2.INF
|
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