0 votes

Is it possible for me to make Area2D gets duplicated and spawns like 20 pixels forward the currently area2d and repeat that progress and so it spawns like 10 pixels higher and lower so its random?

asked Jan 27 in Engine by unknowndexy (17 points)

1 Answer

+1 vote
Best answer

Sure, that can be done.

I might recommend something like:

  • Create a standalone scene containing the Area2D and anything else you want to be a part of your spawned instances.
  • In a script on some controlling scene, preload your Area2D scene using something like var area2d = preload("res://Scenes/Area2D.tscn")

    • Create a loop that will spawn as many instances as you want. You could use something like this to drive the loop for i in range(10): (that'll execute the code in the loop 10 times)
  • In the loop, create a new instance of your preloaded scene using var newArea = area2d.instance()
  • Also in the loop, position the newly instanced scene at some random location based on logic of your choice. With your new, random x and y position selected, you can place the new item there using newArea.postion = Vector2(newX, newY)

That's really about it. Just season to taste...

answered Jan 27 by jgodfrey (6,576 points)
selected Jan 29 by unknowndexy
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.