0 votes

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):

func initiate_target():
    if get_tree().current_scene.get_node_or_null("Player/HitBox") != null:
        target = get_tree().current_scene.get_node("Player/HitBox")
        target = null

func navigate():
    velocity = global_position.direction_to(path[1]) * mob_speed
    if position == path[0]:

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)
Godot version latest
in Engine by (36 points)

1 Answer

0 votes
Best answer

You're removing entries from path, but you're not checking if there's none left.

BTW, according to the docs, getsimplepath is deprecated.

by (1,053 points)
selected by

Thank you so much!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.