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

Pre calculation and then playback

Discussion in 'Scripting' started by FisherM, Mar 10, 2015.

  1. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    i am prototyping with an idea using typical turn based mechanics where everyone takes their turn at the same time and then the game plays for 10 seconds and then everyone takes their turns again.

    I had the idea that in order to allow for a much greater magnitude of units moving I could under the hood calculate for x many seconds (the players will see "calculating...") and then the players watch 10 seconds of of simulation but without the overhead of any raycast/spherecast/pathfinding/calculations. Does anyone have any suggestion as to how I would actually do all of this?

    I can imagine building up a dictionary with events and querying as units move
     
  2. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    a reply would be nice
     
    CDMcGwire likes this.
  3. Random_Civilian

    Random_Civilian

    Joined:
    Nov 5, 2014
    Posts:
    55
    IMO your question is slightly vague. For one, what are you calculating? Line of sight? What dimensions are you working in? Anyway, it sounds a lot like the game Frozen Synapse if that helps.
     
  4. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    Yes frozen synapse and breach and clear is what I had in mind. Everything would be calculated including los, combat collisions ect so that the only thing having to be handled when played is the applying of thesw things so actually moving changing animation states
     
  5. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    I do something very similar and this concept works very well - I use a native library to do all my heavy lifting so the pre calculation typically takes less than 100ms. My implementation is something along the lines of:

    • Create an enum of all possible states for all possible objects.
    • Create a list of all events which are timestamped for when they occur (timestamp is the time since the simulation start)
    • Iterate over the list of events and on each update loop update each object based on its current state.

    Imagine the list of imaginary events with totally bogus figures:

    1. T + 0.1, object A, current state=stopped, new state = moving vector(2f, 1f, 3f)
    2. T + 0.3, object B, current state=stopped, starts moving vector(1f, 0f,8f)
    3. T + 2f, objects A and B collide new a.vector(8, 2, 4); new b.vector(1, 9, 2);
    4. T + 5f, object A, current state = moving, new state stopped, a.vector(0,0,0)
    5. T + 5.2f, object B,current state = moving, new state stopped, new state stopped b.vector(0,0,0)
    Then on each update each object is updated based on its current state and the time in that state. You'd obviously need more state than I've illustrated here, but you get the idea.
     
  6. Random_Civilian

    Random_Civilian

    Joined:
    Nov 5, 2014
    Posts:
    55
    I would do something similar to larku.
    If real time physics performance is really an issue, it sounds simple enough to be written by you (just a simple line and rectangle or circle intersection) and calculated in a separate thread.