- Home /
Replay system for android, need help with precision (framerate problem)
I have a simple replay system to "replay" the game. (the game I'm making is for android)
It's made so that it saves the positions of two joysticks to a file when recording, and when playing back it reads those positions and sets them to the joysticks.
Now the replay system "works", but if I play for a couple of minutes, I lose some of the accuracy (e.g. if in recording my last position was (14, 1, 14), when playing back it varies by -1, +1). I'm guessing this is because the framerate of the game keeps changing.
I don't have much experience with Unity so I'm wondering how I should go about fixing this.. So far I've tried setting the targetFramerate of the application, but that dosn't seem to help.
The closest I've goten is by setting Time.captureFramerate, the variaton then was in decimals, about 0.2 after two minutes, but I don't think this is an option on weaker devices + (messy?).
Now I need someone to give me a nudge in the right direction, or atleast to tell me that making this 100% accurate is impossible. Below is how the reply system works:
Recording..
- Start a Coroutine that saves position every frame
Coroutine:
- keep running while recording
- calls a couple of simple functions, that save the joysticks positions to arrays and later to a file
- has a yierd return null (every frame?)
Playing recording..
- Start 3 Coroutines
1. Coroutine reads the positions from a text file and fills the two arrays
- keep running until EOF (replay file)
- reads positions from text and fills arrays
- has a yield return null
2. Coroutine reads information from the arrays and sets the position of joysticks
- keep running while array has "something" inside ( I use a queue for the array, POPing and PUSHing )
- reads from array and sets joystick position
- has a yield return null
3. Coroutine, this one is the same as the second one, just a diffrent joystick
(The joysticks that I'm reading positions from are the joysticks from the Standard Assets (Mobile) package, if I understand correctly they only change positions every frame).
EDIT: The write, read is working fine. ( every value that gets writen, later gets read)
Evaluating Physics/collision and doing any sort of floating point work you always have a certain margin of error. Because of simplifications that allow things to be done in real-time, nothing will ever really happen the exact same way.
I suggest ins$$anonymous$$d of saving the "input", you save the "output" aka the position of objects and interpolate.
Yeah I realize that physics always give some error, but the game I'm making is being designed so that it barely uses any physics.
Anyways, the problem here is framerate-wise since if I keep the framerate at a constant I get almost no error, but the bigger the variation of framerate the bigger the error.
I'm just looking for a way to make this framerate independant.
Answer by SmileQ · Nov 18, 2013 at 11:49 AM
Nevermind, I got it to work. Yeah I did try using the physics loop before but it didn't work, now I finnaly realized why not.. I forgot to change the joysticks position update loop into a physics loop.