0

I am making my first 3d fps in Godot and I don't understand how to spawn enemies in a general area. If someone could show me a tutorial or something that would be great.

SolerG0d
  • 11
  • 1

1 Answers1

0

Make a scene with only your enemy character, Give it control scripts as needed (movement, etc), and save it as a scene (Ex: myEnemy.tscn).

In your main script (or wherever you're calling it from), load the enemy scene and store it as a variable by writing:

onready var loadedEnemy = preload("res://myEnemy.tscn")

Then in your _process() or _ready() function (depending on what you need it for):

  1. Instance the enemy by writing

var enemy = loadedEnemy.instance()

  1. Add the instance to the scene with

add_child(enemy)

3.Specify the location of the enemy placement. For a random placement somewhere in a 10 x 10 area on the ground level (Y=0) by writing

enemy.transform.origin = Vector3( rand_range(0,10), 0, rand_range(0,10) )

You can also specify rotation with

enemy.transform.basis = Vector3(90deg, 0, 0) (example)

You can add more enemies by repeating these steps beginning from var enemy = loadedEnemy.instance() (Ex: The next enemy would be var enemy2 = loadedEnemy.instance())

If you need them to appear at different times, add them in the on_timer_timeout() function of a different Timer nodes.

Good Luck

Christopher Bennett
  • 803
  • 1
  • 8
  • 20