Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Manuel Paulucci |
I’m trying to make the enemy follow the player following a tutorial, but I get an error when starting { invalid get index ‘has’ (on base: ‘scene tree’) }.
This is my code
extends KinematicBody2D
export(int) var SPEED: int = 150
var velocity: Vector2 = Vector2.ZERO
var path: Array =
var levelNavegation: Navigation2D = null
var player = null
onready var line2d = $Line2D
func _ready():
yield(get_tree(), “idle_frame”)
var tree = get_tree()
if tree.has.group(“Labe”):
levelNavegation = tree.get_nodes_in_group(“LevelNavigation”)[0]
if tree.has_group(“Player”):
player = tree.get_nodes_in_group(“player”)[0]
func _physics_process(delta):
line2d.global_position = Vector2.ZERO
if player and levelNavegation:
generate_path()
navigate()
move()
func navigate():
if path.size() > 0:
velocity = global_position.direction_to(path[1]) * SPEED
if global_position == path[0]:
path.pop_front()
func generate_path():
if levelNavegation != null and player != null:
path = levelNavegation.get_simple_path(global_position, player.global_position, false)
line2d.points = path
func move():
velocity = move_and_slide(velocity)