Advertisement
Guest User

Untitled

a guest
Apr 8th, 2022
17
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends KinematicBody2D
  2.  
  3. var motion: Vector2 = Vector2.ZERO
  4. var speed = 110
  5. var player = null
  6. var in_attack_range = false
  7. var path = []
  8. var level_navigation: Navigation2D = null
  9.  
  10. onready var line2d = $Line2D
  11.  
  12. func _ready():
  13. yield(get_tree(), "idle_frame")
  14. var tree = get_tree()
  15. if tree.has_group("level_navigation"):
  16. level_navigation = tree.get_nodes_in_group("level_navigation")[0]
  17. if tree.has_group("player"):
  18. player = tree.get_nodes_in_group("player")[0]
  19.  
  20. func _physics_process(delta):
  21. line2d.global_position = Vector2.ZERO
  22. move_and_slide(motion)
  23.  
  24. func _navigate():
  25. if path.size() > 0:
  26. print(path[1], " Target point")
  27. motion = self.position.direction_to(path[1]) * speed
  28. for point in path:
  29. if position == point:
  30. print(point, " On point")
  31. if global_position == path[0]:
  32. path.remove(0)
  33. print(path)
  34. #_update_path()
  35.  
  36. func _update_path():
  37. if level_navigation != null and player != null and !path.empty():
  38. path = level_navigation.get_simple_path(position, player.global_position, false)
  39. line2d.points = path
  40. print("New path generated (updated)")
  41. print(path)
  42.  
  43. func _generate_path():
  44. path = []
  45. if level_navigation != null and player != null:
  46. path = level_navigation.get_simple_path(position, player.global_position, false)
  47. line2d.points = path
  48. print("New path generated")
  49. print(path)
  50.  
  51. func _clear_path():
  52. path = []
  53.  
  54. func _sentry():
  55. motion = Vector2.ZERO
  56.  
  57. func _on_Area2D_body_entered(body):
  58. if "Bullet" in body.name:
  59. queue_free()
  60.  
  61.  
  62. func _on_Aggro_Range_body_entered(body):
  63. if "Player" in body.name:
  64. in_attack_range = true
  65.  
  66.  
  67. func _on_Aggro_Range_body_exited(body):
  68. if "Player" in body.name:
  69. in_attack_range = false
Advertisement
RAW Paste Data Copied
Advertisement