Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Nizil |
extends KinematicBody2D
export var mob_speed = 200
var velocity = Vector2()
var path = []
var navigation : Navigation2D = null
var target = null
func _ready():
navigation = get_tree().current_scene.get_node("Navigation")
func _physics_process(delta):
initiate_target()
generate_path()
navigate()
chase()
func initiate_target():
if get_tree().current_scene.get_node_or_null("Player/HitBox") != null:
target = get_tree().current_scene.get_node("Player/HitBox")
else:
target = null
func navigate():
velocity = global_position.direction_to(path[1]) * mob_speed
if position == path[0]:
path.pop_front()
func generate_path():
if navigation != null and target != null:
path = navigation.get_simple_path(position, target.global_position, false)#this var
func chase():
velocity = move_and_slide(velocity)
Someone can tell me, why path Array don’t have data from get_simple_path()? i’m don’t have any idea about this trouble. I tried to print path and it’s returned empty array.
This may be a problem with how you are getting your Navigation node.
Why not just use $Navigation
instead of get_tree().current_scene.get_node("Navigation")
magicalogic | 2022-11-14 04:57
No, get_node()
it’s just like $. And I tried to write $Navigation
. It’s seems like get_simple_Path()
can’t use array.
Nizil | 2022-11-14 08:15