Guest User

SCRIPT ATTACHED TO MAIN LEVEL NODE

a guest
Mar 1st, 2025
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Node2D
  2. @export var enemy1Scene: PackedScene
  3.  
  4. # Called when the node enters the scene tree for the first time.
  5. func _ready() -> void:
  6.     pass # Replace with function body.
  7.  
  8.  
  9. # Called every frame. 'delta' is the elapsed time since the previous frame.
  10. func _process(_delta: float) -> void:
  11.         pass # Replace with function body.
  12.        
  13.        
  14. func _on_basic_spawn_timer_timeout():
  15.     # Create a new instance of the Mob scene.
  16.     var enemy1L = enemy1Scene.instantiate()
  17.  
  18.     # Choose a random location on Path2D.
  19.     var enemy1_spawn_location = $enemySpawnPath/enemySpawnLoc
  20.     enemy1_spawn_location.progress_ratio = randf()
  21.  
  22.     # Set the mob's direction perpendicular to the path direction.
  23.     var direction = enemy1_spawn_location.rotation + PI / 2
  24.  
  25.     # Set the mob's position to a random location.
  26.     enemy1L.position = enemy1_spawn_location.position
  27.  
  28.     # Add some randomness to the direction.
  29.     direction += randf_range(-PI / 4, PI / 4)
  30.     enemy1L.rotation = direction
  31.  
  32.     # Choose the velocity for the mob.
  33.     var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
  34.     enemy1L.linear_velocity = velocity.rotated(direction)
  35.  
  36.     # Spawn the mob by adding it to the Main scene.
  37.     add_child(enemy1L)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment