The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+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():
    pass 


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

What am I doing wrong and what should I do?

in Engine by (196 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)
    move_to(Player.global_transform.origin)
    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
        else:
            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 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.