hi, can anyone help me?
I have a little problem, for some reason it throws an error when I try to use getsimplepath() in the generate_path() function. The path, for some reason, is not written to the array and gives an error when used in the navigate() function.
extends KinematicBody2D
export var mob_speed = 200
var velocity = Vector2()
var path : Array = []
var navigation : Navigation2D = null
var target = null
func _ready():
navigation = get_tree().current_scene.get_node("Navigation")
func _physics_process(delta):
initiate_target()
generate_path()
navigate()
chase()
func initiate_target():
if get_tree().current_scene.get_node_or_null("Player/HitBox") != null:
target = get_tree().current_scene.get_node("Player/HitBox")
else:
target = null
func navigate():
velocity = global_position.direction_to(path[1]) * mob_speed
if position == path[0]:
path.pop_front()
func generate_path():
if navigation != null and target != null:
path = navigation.get_simple_path(position, target.global_position, false)
func chase():
velocity = move_and_slide(velocity)