im an a beginner dev still experiment on stuff. im trying to create a spawner using the position2d but some code result as "First argument of yield() is null.". is there a way to fix this.
here is the pos2d code
extends Position2D
signal spawned(spawn)
export(PackedScene) var spawnling_scene
export var spawnrad = 100
func _on_EnemyTimer_timeout():
var spawnling = spawnling_scene.instance()
add_child(spawnling)
spawnling.global_position = global_position
return spawnling
and here is the enemy script
> extends KinematicBody2D class_name Enemy
>
> export var speed = 100
>
> onready var enemy = get_node_or_null("/root/world/enemy") onready var
> player = get_node_or_null("/root/world/player") var velocity =
> Vector2.ZERO var path: Array = [] # contain destinations positions var
> nav = null var thereshold = 16
>
> func _ready():
> yield(owner, "ready")
> nav = owner.nav
>func _physics_process(_delta)
> if path.size() > 0:
> move_to_target()
> look_at(player.global_position)
>func move_to_target():
> if
> global_position.distance_to(path[0]) < thereshold:
> path.remove(0)
> else:
> var direction = global_position.direction_to(path[0])
> velocity = direction * speed
> velocity = move_and_slide(velocity)
>func get_target_path(target_pos):
> path = nav.get_simple_path(global_position, target_pos, false)