Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Zaorish | |
Old Version | Published before Godot 3 was released. |
Hi,
I’m trying to repeat godot-pathfinding2d-demo, but my
points = get_node("../Navigation2D").get_simple_path(get_global_pos(), get_global_mouse_pos(), false)
returns empty array all the time. Can someone help me to understand where is the problem?
Scenes:
tileset.tscn
tileset (Node)
->floar (Sprite)
→ ->NavigationPolygonInstance
->wall
→ ->StaticBody2D
→ -> ->CollisionShape2D
player.tscn
player (RigidBody2D)
->player (Sprite)
->CollisionShape2D
level.tscn
level (Node2D)
->Navigation2D
→ ->TileMap
->player
player.gd
extends RigidBody2D
export var speed = 200
const eps = 1.5
var points = []
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
points = get_node("../Navigation2D").get_simple_path(get_global_pos(), get_global_mouse_pos(), false)
print (points)
if points.size() > 1:
var distance = points[1] - get_global_pos()
var direction = distance.normalized()
if distance.length() > eps or points.size() >2:
set_linear_velocity(direction*speed)
else:
set_linear_velocity(Vector2(0,0))
update()
func _draw():
if points.size() > 1:
for p in points:
draw_circle(p - get_global_pos(), 8, Color(1,0,0))
I ran into this problem too, but not exactly sure what the problem with yours is. Try checking your tiles make sure the navigationpoly is exactly the size of the texture and make sure its enabled.
haz | 2017-07-27 20:30