This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

How I can move a KinematicBody to a target using Navigation.get_simple_path function and GDScript in a 3D space?
Thanks in advanced.

Godot version 3.3
in Engine by (353 points)

1 Answer

+1 vote
Best answer

Here is a 2D analog for what you're trying to accomplish:

onready var nav = $Navigation2D
var destination = null
var navigation_path = []

func _physics_process(delta: float) -> void:
    if destination:
        move_towards_position(destination, delta)
        # if we're close enough, call it good
        if self.position.distance_squared_to(destination) < 5:
            self.position = destination
            destination = null
    elif not navigation_path.empty():
        destination = navigation_path.pop_front()

func _input(event: InputEvent) -> void:
    var start_position = self.position
    var end_position = get_end_position(event)
    var path = Array(nav.get_simple_path(start_position, end_position))
    if path.empty():
        var always_starting_position = path.pop_front()
        navigation_path = path

Obviously, you'll need to implement move_towards_position() and get_end_position(). Something to keep in mind: get_simple_path() wants and returns points in local coordinate space, if i recall correctly, moving in 3D generally wants points in global space.

by (3,906 points)
selected 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.