Navigation node and get simple path

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345

i have this code for use get_simple_path()

extends KinematicBody

onready var player = get_node("KinematicBody2")
onready var nav = get_parent()
var path = nav.get_simple_path(self.translation,player.global_transform.origin)

func _ready():

func _physics_process(delta):
	path = nav.get_simple_path(global_transform.origin,player.global_transform.origin)

What am I doing wrong and what should I do?

Maybe it has something to do with the first parameter in the method nav.get_simple_path(self.translation,player.global_transform.origin)? Maybe the first parameter should be global_transform.origin?

Ertain | 2020-10-18 17:39

:bust_in_silhouette: Reply From: KurtBlissZ

I only done 3d navigation once awhile ago but looking at my project you need to calculate the vector to the next point of the path. Here’s just a quick copy and paste

func state_chase(delta):
if path_hit_point == true:
	print("path_hit_point ", path_hit_point)
	path_hit_point = false

func move_to(target_pos):
	path = nav.get_simple_path(global_transform.origin, target_pos)
	path_ind = 0

func path_process():
	if path_ind < path.size():
		var move_vec = (path[path_ind] - global_transform.origin)
		if move_vec.length() < 0.1:
			path_ind += 1
			if path_ind > 2:
				path_hit_point = true
			move_and_slide(move_vec.normalized() * move_speed, Vector3(0, 1, 0))

Edit: Sorry I’m a little dumb drop that, here’s a tutorial then one issue I ran into is that I accidentally rotated the navigation node and I was having weird effects.