Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ashish |
How do I access the points in the path of Navigation2D get_simple_path?
I am unable to access the points when I print the points of the PoolVector2Array. The path is showing a null array. When I convert the PoolVector2Array to an Array, and then print the array that has the points of the path, I get a Vector2(0,0) output. What am I doing wrong?
Please help.
Here is my code:
extends Node2D
onready var start_point = $Sprite
onready var finish_point = $Sprite2
onready var navig = $Navigation2D
onready var line = $line
var start = Vector2(0,0)
var finish = Vector2(0,0)
var path = PoolVector2Array()
func _ready():
finish =finish_point.position
start = start_point.position
print(start, finish)
path = navig.get_simple_path(start, finish)
print(path)
var vectors = PoolVector2Array(Array([path]))
print(vectors)
This is the output:
(186, 260)(1298, 260)
[(0, 0)]
did you set up the navigation nodes correctly?
are those point inside the navigation polygon?
Andrea | 2021-01-16 13:14
Hi,
Thanks for your reply. Attaching how I have set up the Navigation2D node and NavigationPolygonInstance.
The output that I get with the same code and this setup is:
(408, 200)(1296, 200)
[(408, 200), (1296, 200)]
[(0, 0)]
ashish | 2021-01-17 15:15
can you share the project folder entirely?
from the picture is not clear yet
Andrea | 2021-01-17 16:23
Hi,
Thanks for looking into my problem.
How does one share the project folder entirely?
ashish | 2021-01-17 17:46
ashish | 2021-01-17 17:50
The aim of the app is to move the left TouchButton (will change it to KinematicBody) to the right in a straight line. If the player moves vertically up or down as per the move of the mouse button, then bring the player to the nearest point of the path.
ashish | 2021-01-17 18:03