You are getting an error because the variable “direction”, is being declared inside an if statement:
if currentnode < path.size():
var direction : Vector3 = path[currentnode] - globaltransform.origin
because it’s declared in an if statement, the variable can’t reach the rest of the function. You should declare it either at the top of the function, or at the top of the script. You should change the script to
onready var nav = $"../Navigation" as Navigation
onready var player = $"../player" as KinematicBody
var path = [0]
var current_node = 0
var speed = 2
func ready():
pass
func _physicsprocess(delta):
var direction = Vector3()
updatepath(player.globaltransform.origin)
if currentnode < path.size():
direction : Vector3 = path[currentnode] - globaltransform.origin
if direction.length() < 1:
currentnode += 1
else:
moveandslide(direction.normalized()* speed)
func updatepath(targetposition):
path = nav.getsimplepath(globaltransform.origin, targetposition)