Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Load Enemies on a large (tile-)map

Discussion in 'Getting Started' started by Jaycey, Feb 11, 2021.

  1. Jaycey

    Jaycey

    Joined:
    Feb 5, 2021
    Posts:
    4
    Hi,

    After some testing and playing around, I started a tilemap-based 2D top-down RPG game. I have created a kinda large map and now I'm willing to populate it with NPC's and enemies.
    My enemies are ScriptableObjects, spawned by a MonsterSpawner-Prefab which are intented to approach the player on sight.

    On my whole map, I'm planning to place dozens of Spawners. My idea was that these spawners are only supposed to spawn enemies, when the player is close enough.

    And here is the clue: Is it any performant to calculate the distance to dozens of spawners each frame? Or would you recommend another approach or mechanism to efficiently populate my map with enemies?
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    How does your character move around the map? Is it like the old Final Fantasy / Pokemon / Uncharted Waters where they move one tile at a time? Or more like the Zelda games where it's basically free movement?

    If it's the first one, I'd absolutely have an event fire when the player stops moving that can be consumed by the Spawner system to determine if enemies should be generated. If it's the second, you'll have to do it more frequently (doesn't have to be in an Update... could be every few seconds or something), but I would do it in one manager that has access to all of the spawn points. The manager system knows about the player and their position, and can determine if it should spawn enemies and where they should be spawned.
     
    Jaycey likes this.
  3. Jaycey

    Jaycey

    Joined:
    Feb 5, 2021
    Posts:
    4
    It's more like the old Zelda games, you have a free, seamless movement around all the tiles.
    I like your idea of a general SpawnManager, measuring distances and controlling the spawns in fixed frequency...

    I will try that out, thank you!
     
    Schneider21 likes this.
  4. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Can you release your finished game when it's done? I like the old style RPGs :)
     
    Jaycey likes this.
  5. Jaycey

    Jaycey

    Joined:
    Feb 5, 2021
    Posts:
    4
    @RichAllen2016 for sure, but since I'm a Unity beginner doing this in my spare free time this gonna take quite a while :D