0 votes

This script is used so an enemy follows the player around and when watching a video it said to use this line of code

func moveto(targetpos):
path = nav.getsimplepath(globaltransform.origin, targetpos)
path_node = 0

But the debugger said "getsimplepath is a nonexistent function"
This is my entire code for the enemy

extends KinematicBody

var path = []
var path_node = 0

var speed = 10

onready var nav = get_parent()
onready var player = $"../NewFPS"

func _ready():
pass

func physicsproscess():
if pathnode < path.size():
var direction = (path[path
node] - globaltransform.origin)
if direction.length() < 1:
path
node += 1
else:
moveandslide(direction.normalized() * speed, Vector3.UP)

func moveto(targetpos):
path = nav.getsimplepath(globaltransform.origin, targetpos)
path_node = 0

func onTimertimeout():
move
to(player.global_transform.origin)

Godot version 3.4
in Engine by (12 points)

1 Answer

0 votes

get_simple_path(...) is a valid function on a Navigation or Navigation2D node. In your code, you seem to be trying to get a reference to some kind of navigation node via:

onready var nav = get_parent()

I can only assume that the node being returned by get_parent() in this case is not the navigation node you think it is.

You haven't shared your scene tree, but for that code to work, the above script would need to be associated with a node that is a child of the expected navigation node. I assume that's not the case here.

To check that, I'd suggest that you verify the node that's being stored in your nav reference. This should tell you...

func _ready():
    print('nav node is a ' + nav.get_class())

I assume you'll find that it's not a Navigation-type node... In that case, you need to reference the correct node.

by (12,460 points)
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 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 webmaster@godotengine.org with your username.