Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mydaz |
How to instantiate a scene in the script in this script, At the moment he is instantiating the player through the player_container, and this is causing a lot of bugs because if I put 1 more enemy he bugs completely, HELP
extends KinematicBody2D
var run_speed = 50
var velocity = Vector2.ZERO
var player = preload("res://player.tscn").instance()
onready var player_container = get_node("player_container")
var is_entered = null
func _physics_process(delta):
velocity = Vector2.ZERO
if is_entered:
velocity = (player.position - position).normalized() * run_speed
$Sprite.play("run")
$Sprite.flip_h = false
else:
$Sprite.play("idle")
velocity = move_and_slide(velocity)
func _on_Area2D_area_entered(area):
is_entered = area
func _on_Area2D_area_exited(area):
is_entered = null