Guest User

Untitled

a guest
Sep 19th, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends NavigationAgent3D
  2.  
  3. var pdelta:float;
  4. var pframe:int=0
  5. func _ready() -> void:
  6.     var agent: RID = get_rid()
  7.     target_position = (get_parent() as Node3D).global_position
  8.     max_speed = get_parent().get_meta("ConeSpeed",4.20)
  9.     Globals.DebugPrint("Cone Position: "+str((get_parent() as Node3D).global_position)+" (init)")
  10.  
  11. func _physics_process(delta: float) -> void:
  12.     pdelta =delta
  13.     pframe+=1
  14.     if (pframe % 1 == 0):
  15.         Globals.DebugPrint("Cone Position: "+str((get_parent() as Node3D).global_position)+" pframe: "+str(pframe))
  16.         Globals.DebugPrint(target_position)
  17.     if NavigationServer3D.map_get_iteration_id(get_navigation_map()) == 0:
  18.         return
  19.     #if is_navigation_finished():
  20.         #return
  21.     var new_velocity: Vector3 = (get_parent() as Node3D).global_position.direction_to(get_next_path_position() * max_speed)
  22.     #new_velocity = (get_parent() as Node3D).global_position.direction_to(get_next_path_position()*max_speed)
  23.     if (pframe % 10 == 0):
  24.         Globals.DebugPrint(new_velocity)
  25.     (get_parent() as Node3D).global_translate(new_velocity)
  26.     #_on_velocity_computed(new_velocity)
  27.     pass
  28.  
  29. func _on_navigation_finished() -> void:
  30.     #Globals.DebugPrint("New navigation")
  31.     #var pos = (get_parent() as Node3D).global_position
  32.     #var navradius = (get_parent() as Node3D).get_meta("nav_radius",1.0)
  33.     #pos.x += randf_range(-navradius,navradius)
  34.     #pos.y += randf_range(-navradius,navradius)
  35.     #pos.z += randf_range(-navradius,navradius)
  36.     #target_position = pos
  37.     pass
  38.  
  39.  
  40. func _on_velocity_computed(safe_velocity: Vector3) -> void:
  41.     #(get_parent() as Node3D).global_position =(get_parent() as Node3D).global_position.move_toward((get_parent() as Node3D).global_position + safe_velocity, pdelta * max_speed)
  42.     (get_parent() as Node3D).global_translate(safe_velocity)
  43.  
  44. func _on_target_reached() -> void:
  45.     Globals.DebugPrint("New navigation (TR)")
  46.     var pos = (get_parent() as Node3D).global_position
  47.     var navradius = (get_parent() as Node3D).get_meta("nav_radius",1.0)
  48.     Globals.DebugPrint(pos)
  49.     pos.x += randf_range(-navradius,navradius)
  50.     pos.y += randf_range(-navradius,navradius)
  51.     pos.z += randf_range(-navradius,navradius)
  52.     target_position = pos
  53.     while (not is_target_reachable()):
  54.         pos = (get_parent() as Node3D).global_position
  55.         pos.x += randf_range(-navradius,navradius)
  56.         pos.y += randf_range(-navradius,navradius)
  57.         pos.z += randf_range(-navradius,navradius)
  58.         target_position = pos
  59.     Globals.DebugPrint(pos)
  60.     Globals.DebugPrint(target_position)
  61.  
Advertisement
Add Comment
Please, Sign In to add comment