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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

forward/rewind/jump to time in action sequence

Discussion in 'Game Design' started by LeftyRighty, Aug 12, 2015.

  1. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    I'm toying with the idea of a "puzzle/rts/tower defence" concept where you can plan out your units' movements, activate abilities, issues orders etc. against a preset target with some static defences (bunkers, gun emplacements), some dynamic units (tanks, infantry etc. move to intercept your units).

    The core bit I can't figure out is how to implement a "scrub forward / backward" feature so you can play out the current plan in real time, fast forward (timescale stuff not so tricky) but also jump to a time index (erm... help!) as you would a video.

    Any pointers on the data structure the actions/events need to be held in in order to facilitate this? I'm looking through the AI/search/planning concepts and feeling a little lost.



    edit: was thinking more about this last night, I guess it's would need to be something along the lines of an animation dopesheet, so storing the position/direction/health/whatever at key time frames and either interpolating a value between the keyframes (where the unit is at time t would be a mid point between two waypoints) or just taking the previous value (health, ammo etc.)
     
    Last edited: Aug 13, 2015
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You could just use a set of animation curves. Simply store the relevant values from time to time, then read the interpolation off the curve to see where the units should be.
     
  3. SpaceMammoth

    SpaceMammoth

    Joined:
    Jan 2, 2013
    Posts:
    220
    As you and BoredMormon say you need to store a time series of your games state, there is no avoiding this. The way I would do it is to make sure that all important game state of your game objects is encapsulated in your a game object base class and then implement a generic mechanism to copy this game state to a collection which is your stored time series. I would use serialisation, but there are many ways to extract and store the game state. As you say use interpolation between stored values to retrieve the game state at a given time, and then have unity move/create/remove visual objects to place you at that point. What gets hard is making sure your game model can be entirely serialised/stored in this way.

    I am doing this myself for Mammoth Gravity Battles, as one major feature currently missing is the capability to replay the turn's action - its basically the same problem.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    There is one way. You can use a deterministic system instead of an iterative one. Kerball uses this to great effect for orbital mechanics. With a deterministic system you can simply query the system to see where something is. It does mean completely rewriting a to of physics through. And it may not be applicable to your game type.
     
  5. Batman_831

    Batman_831

    Joined:
    Oct 17, 2014
    Posts:
    106
    Just curious, If I am making a game where player presses a button to rewind ( like in Prince Of Persia ) would I need to use animation curves everywhere for each of values (like 1 for x-y-z player position, 1 for x-y-z player rotation, and many others for different game mechanics which need to be rewinded)? Isn,'t there a more efficient solution to this maybe?
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Deterministic physics and recording input. It will need to be all custom, unity is not very good at deterministic.
     
    Batman_831 likes this.
  7. SpaceMammoth

    SpaceMammoth

    Joined:
    Jan 2, 2013
    Posts:
    220
    Relying on determinism only works for entirely deterministic closed systems like orbital mechanics. We have player input which is not deterministic and we have a non-closed system where game objects are created and removed. Take this example - you have 3 objects; a gun, a bullet and an alien.

    At time 0 - you have a gun and an alien
    At time 1 - you have the bullet, it impacts the alien, both are removed
    At time 2 - you only have a gun

    You cannot rewind this game state to a previous time from time 2, without having stored some details of what has happened in the time series. There is no other way. Even my game suffers from this, its entirely deterministic celestial mechanics, like Kerbal, however I cannot rewind time, and reverse the physics because I have lost information about the objects that have been removed and would need to know what and when to re-introduce them.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Determinism is common in multiplayer RTS games. Seen the replay mechanism from Age of Empires 2? The system was produced using deterministic physics and recording every player input.

    It requires a ton of work, including fixing the time step and making physics granular. But it generally will require less data storage.