Search Unity

Ghost Character for 2D Flying Game

Discussion in '2D' started by LeeDenbigh, Aug 2, 2015.

  1. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
    In my head this seems really easy, but I just can't figure it out. Each round (in the game) is 30 seconds. I really would love to add a ghost to the game so that when the next round is played they can see how they did in the last round, it would make it so much more fun...

    How do I go about saving the position of the player object to an array on each frame. And also, how would I save the array in player prefs so that it can be used over and over again...

    Is this even possible?
     
  2. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
  3. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    You can use this solution here to store arrays in the preferences. http://wiki.unity3d.com/index.php/ArrayPrefs2

    But you understand that the volume of data may be enormous.
    As an optimisation, you need to understand that the player position will not change every frame. Reduce the number of entries in the array by storing the position only when it changes (of-course this need to save the time in the array also). Evaluate the cost of storing in both situations before making a decision on which version you want to use.

    You could also setup the data to save only when the player deviates from a straight line. Rest of the time the system interpolates linearly between the two stored points.
     
  4. LeeDenbigh

    LeeDenbigh

    Joined:
    Jul 7, 2014
    Posts:
    48
    Thanks for the reply @sandboxed.

    The best this about this is that the player only ever goes in one direction (up).

    What I was thinking is to just record the position over the time 30seconds of play. So it will only start recording as the player starts to more and the clock counts down. Then when the player restarts and presses play, just start the ghost to use the positions stored?
     
  5. sandboxed

    sandboxed

    Unity Technologies

    Joined:
    Apr 6, 2015
    Posts:
    95
    I don't see a reason why that would not work. Give it a shot.

    But I think the amount of data generated will still be a problem. Get it to work first, and then look around on how to optimise it.

    Good luck!
     
    theANMATOR2b likes this.