fixed the path rebuilding lag

This commit is contained in:
2026-02-08 02:10:23 +11:00
parent fd9b62faba
commit e441a121ff
26 changed files with 629 additions and 385 deletions

View File

@@ -138,7 +138,7 @@ func _physics_process(delta: float) -> void:
func consider_leap(direction: Vector3) -> void:
var node: FlowNode = check_jump(character.global_position + (direction * jump_distance))
var node: FlowNodeData = check_jump(character.global_position + (direction * jump_distance))
if node:
var expected_distance_remaining: float = calculate_distance_to_goal(node)
expected_distance_remaining += (character.global_position + (direction * jump_distance)).distance_to(node.global_position)
@@ -153,8 +153,8 @@ func finish_jump() -> void:
jumping = false
func check_jump(destination: Vector3) -> FlowNode:
var closest_point: FlowNode = flow_field.get_closest_traversable_point(destination)
func check_jump(destination: Vector3) -> FlowNodeData:
var closest_point: FlowNodeData = flow_field.get_closest_point(destination, true, false)
if !closest_point.best_path or closest_point.global_position.distance_to(destination) > 1.2:
return null
return closest_point.best_path

View File

@@ -4,7 +4,7 @@ extends EnemyMovement
#var path: Curve3D
#var path_progress: float = 0.0
var flow_field: FlowField
var next_node: FlowNode :
var next_node: FlowNodeData :
get():
return next_node
set(value):
@@ -16,16 +16,16 @@ var next_node: FlowNode :
#TODO: make deterministic random
var x: float = randf_range(-1, 1)
var y: float = randf_range(-1, 1)
if Vector3(next_node.global_position.x + x, next_node.global_position.y, next_node.global_position.z + y).distance_to(next_node.global_position) <= 1.0:
if Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y).distance_to(next_node.position) <= 1.0:
found_point = true
next_pos = Vector3(next_node.global_position.x + x, next_node.global_position.y, next_node.global_position.z + y)
next_pos = Vector3(next_node.position.x + x, next_node.position.y, next_node.position.z + y)
var next_pos: Vector3
func _ready() -> void:
super._ready()
if flow_field:
next_node = flow_field.get_closest_traversable_point(character.global_position)
next_node = flow_field.get_closest_point(character.global_position, true, false)
#We skip one node so the "start" nodes placed near
#spawners are just usefull for "catching" enemies that are looking
#for a way into the pathfinding graph
@@ -33,14 +33,14 @@ func _ready() -> void:
distance_remaining += calculate_distance_to_goal(next_node)
func calculate_distance_to_goal(node: FlowNode) -> float:
func calculate_distance_to_goal(node: FlowNodeData) -> float:
var distance: float = 0.0
distance += character.global_position.distance_to(node.global_position)
distance += character.global_position.distance_to(node.position)
if node.best_path:
var then_next_node: FlowNode = node.best_path
distance += node.global_position.distance_to(then_next_node.global_position)
var then_next_node: FlowNodeData = node.best_path
distance += node.position.distance_to(then_next_node.position)
while then_next_node.best_path:
distance += then_next_node.global_position.distance_to(then_next_node.best_path.global_position)
distance += then_next_node.position.distance_to(then_next_node.best_path.position)
then_next_node = then_next_node.best_path
return distance