Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Node2D
- @export var enemy1Scene: PackedScene
- # Called when the node enters the scene tree for the first time.
- func _ready() -> void:
- pass # Replace with function body.
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(_delta: float) -> void:
- pass # Replace with function body.
- func _on_basic_spawn_timer_timeout():
- # Create a new instance of the Mob scene.
- var enemy1L = enemy1Scene.instantiate()
- # Choose a random location on Path2D.
- var enemy1_spawn_location = $enemySpawnPath/enemySpawnLoc
- enemy1_spawn_location.progress_ratio = randf()
- # Set the mob's direction perpendicular to the path direction.
- var direction = enemy1_spawn_location.rotation + PI / 2
- # Set the mob's position to a random location.
- enemy1L.position = enemy1_spawn_location.position
- # Add some randomness to the direction.
- direction += randf_range(-PI / 4, PI / 4)
- enemy1L.rotation = direction
- # Choose the velocity for the mob.
- var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
- enemy1L.linear_velocity = velocity.rotated(direction)
- # Spawn the mob by adding it to the Main scene.
- add_child(enemy1L)
Advertisement
Add Comment
Please, Sign In to add comment