Suptract 2 areas and spawn objects in resulting area
I have a 2D top down game. The camera follows the player. I would like to spawn enemies in random positions around the player. But for performance reasons i dont want to fill the whole map with enemies. When enemies are out of view, they will be destroyed and at the same time new enemies will spawn in the new area.
The problem is, that i dont know how to spawn enemies in an area that is the result of the subtraction between the new area and the old area, cuz i dont want to destroy the enemies from the old area which are also in the new area.
Answer by Neengash · Apr 22, 2021 at 04:22 PM
In your case, I think I would address the problem by spawning enemies depending on the player's position.
Since knowing the player position is easy (just need a reference to it), then you can simply add X and Y displacement and determine the new enemies' position.
Your answer
![](https://koobas.hobune.stream/wayback/20220613032555im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you add a Collider2D to a Line Renderer In Unity2D? 0 Answers
Rotating weapon in top-down 2D 0 Answers
Why is my character slightly floating above the ground? 0 Answers
How do I make Polygon Collider 2D more smooth? 0 Answers
Is there any way to trigger a popUp UI when a player steps in a specific set of tiles? 0 Answers