Hello! I'm working on a top-down shooter, and I'm trying to make an enemy that uses pathfinding to make its way to the player
I followed an old tutorial on Youtube and modified the results to fit with my game, but the size of the path table remains a consistent zero regardless of how much distance there is between the player and the enemy
var speed = 150
var nav = null setget set_nav
var path = []
var goal = Vector2()
func _ready():
set_physics_process(true)
goal = get_tree().get_root().get_node("Node2D/Player").position
func set_nav(new_nav):
new_nav = get_tree().get_root().get_node("Node2D/Navigation2D")
nav = new_nav
update_path()
func update_path():
path = nav.get_simple_path(position, goal, false)
if path.size() == 0:
pass
func _physics_process(delta):
print(path.size())
if path.size() > 1:
print("okay?")
var d = position.distance_to(path[0])
if d > 2:
position = position.linear_interpolate(path[0], (speed * delta)/d)
else:
path.remove(0)
Some help with this would be greatly appreciated