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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

RTS Style drag selection.

Discussion in 'Scripting' started by SimpleGiant, Apr 16, 2018.

  1. SimpleGiant

    SimpleGiant

    Joined:
    Dec 22, 2013
    Posts:
    47
    I am making a RTS game and have been struggling with the drag selection. I have found a few ways to do this, but I need the cheapest way to do it. I need it to run smooth with thousands of units, worst case scenario.

    The player should not have entire armies that spans the ranks of 3000, unless they are trolling, but with the combined economy and army composition, I expect the players to have 1200 characters late game.

    I need to know the cleanest way to drag a selection box and multi select units, can someone help?

    I am using c#
     
    tonytopper likes this.
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You could write down the ways you've found / tried, and if anyone has an idea not mentioned, they could post it.
    You could then profile the different methods to see which is best (which you could include here in the thread, for future readers/info, too). :)
     
  3. SimpleGiant

    SimpleGiant

    Joined:
    Dec 22, 2013
    Posts:
    47


    I will do this. I will also run a FPS count on the different ideas as I remake the scripts.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    I ran a stop watch for 1200 sprites (just for kicks), and some simple math / methods I strung together.
    My results were... 471 micro seconds. :)

    Now, disclaimer.. i often mess things up or get it right on try #36 .. but anyways. lol

    I was curious about this myself for some time; also, like you, debated several options in my head.
     
  5. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    2D or 3D? There's a huge difference in the logic required.
     
  6. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    The new job system for 2018.1 has a job type for async raycasts. That could be an option. There's an example of a guy here with 25k particles and raycasts. That's running smoothly enough:
     
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    For the record, I used a UI element as the "drag selection object", and converted the sprites' positions from world to screen space for comparison.
    I've not tested other ideas.

    I can say, though, that to me it makes sense to only run this test 2 or 3 times a second (seems like plenty?), and of course... only while the selection box is active.