Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Nizil |
extends KinematicBody2D
var velocity = Vector2.ZERO
var mob_speed = 200
var path
var global_target
var next_dote
var agent_rid
onready var agent = $NavigationAgent2D
onready var player = get_tree().current_scene.get_node("Player")
func _ready():
agent_rid = agent.get_navigation_map()
set_path_to_the_player()
func _physics_process(delta):
velocity = move_and_slide(velocity)
check_velocity()
func set_path_to_the_player():
global_target = player.global_position
path = Navigation2DServer.map_get_path(agent_rid, global_position, global_target, true) #Everyone node is exists in another scene.
print(path) #it returns []
path.remove(0)
agent.set_target_location(path[0]) #error row
next_dote = agent.get_next_location()
velocity = global_position.direction_to(next_dote) * mob_speed
agent.set_velocity(velocity)
func check_velocity():
if global_position.distance_to(next_dote) < 1:
path.remove(0)
I tried to make normal navigation to melee, but path
is empty everytime. I wrote the comments to rows where error appears. I need help, please.