+1 vote

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?

in Engine by (181 points)

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?

1 Answer

0 votes

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 https://www.youtube.com/watch?v=_urHlep2P84 then one issue I ran into is that I accidentally rotated the navigation node and I was having weird effects.

by (25 points)
edited by
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.