Godot 4
please help I’ve posted before on this but no ones helping, it was fine until I made a tile map then deleted it because it was showing on a separate scene for some reason and now I can’t stop the enemy from spawning on the wrong scene. Enemy 2 is spawning on Enemy 1’s scene.
scene 1 code:
extends Node
@export var mob_scene: PackedScene
func _ready():
$Area2D.start($Marker2D.position)
$Timer2.start()
randomize()
func _process(delta):
pass
func _on_timer_2_timeout():
$Timer4.start()
$Timer3.start()
func _on_timer_4_timeout():
var mob = mob_scene.instantiate()
var mob_spawn_location = $Path2D/PathFollow2D
var direction = mob_spawn_location.rotation + PI /2
mob.position = mob_spawn_location.position
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
add_child(mob)
func _on_timer_3_timeout():
get_tree().change_scene_to_file(“res://mimicdefeated.tscn”)
enemy 1 code:
extends RigidBody2D
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
scene 2 code:
extends Node
@export var mob_scene2: PackedScene
func _ready():
$Timer5.start()
randomize()
func _on_timer_5_timeout():
$Timer6.start()
func _on_timer_6_timeout():
var mob_spawn_location2 = Vector2(600, randf_range(-450 , 450))
var mob2 = mob_scene2.instantiate()
var direction = 0
mob2.rotation = direction
mob2.position = Vector2(600, randf_range(-450 , 450))
var velocity2 = Vector2(randf_range(-150.0, -250.0), 0.0)
mob2.linear_velocity = velocity2.rotated(0)
add_child(mob2)
enemy 2 code:
extends RigidBody2D
func _enter_tree():
$AnimatedSprite2D.play(“run”)
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()