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

Question Dealing with large amount of space ships moving

Discussion in 'Scripting' started by Laser50, Dec 18, 2022.

  1. Laser50

    Laser50

    Joined:
    Aug 28, 2013
    Posts:
    7
    Hi there! I have been at this portion of my game for days now and I believe a lack of skill and knowledge has now hit me hard.

    I am attempting to build a 4X esque space game, which will obviously have a large amount of ships roaming the map, these will likely be ungrouped, seperate AI ships... And a lot of them.

    So far in my code I have built a custom processor so that I can slow down or speed up the processor outside of using time.deltatime, fixeddeltatime or rhe Update() functions.

    The AI currently works rather simple; If we're not looking at the target we will slowly rotate toward looking at said target, and once we are within a few degrees of the target we will start moving toward it.

    I have tried to use rigidbody's velocity. But above 200 instances this will really ruin performance.

    I then tried to use Lerp instead, which works slightly better but still doesn't want to be performant.

    I then tried to do IJobParallelForTransform, and this also seems to work but the performance is also still much to be desired.


    In general, I guess I am looking for tips, tricks and some guidance on the best ways to have a large amount of 'space ships' on the move at the same time, as my above attempts so far haven't given me the results I was hoping for.
    I am aiming to have at least 500 of said ships of different types to be in the game, they may not all be moving and going at the same time but regardless performance is a huge requirement for me here due to the scope I wish to go into at some point and still have it run nicely across a wide range of hardware.

    TL;DR
    Looking for some tips, tricks & guidance to a proper/performant way to have the ability to move around about 300 to 500 space ships in my game, I seem to lack the knowledge to properly do this and hope some experienced folk may have that for me!
     
  2. mopthrow

    mopthrow

    Joined:
    May 8, 2020
    Posts:
    343
    Never had to deal with so many objects myself, maybe you could consider Unity's DOTS.

    The whole playlist:
    https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba


    Maybe a good starting point
     
  3. Laser50

    Laser50

    Joined:
    Aug 28, 2013
    Posts:
    7
    Small update, I have gone back to write a controller esque processor again, I am now able to handle about 10k-15k 'ships' with a minimal loss in performance. So somehow I broke ky last set-up I feel