I am stuck with this problem for a while, so hopefully I will find some answers here.
In this game one really important feature is that player can race with airplane against replays from other players.
The way I do this is that I save position and angle of airplane to file every 10th frame ( because files are gonna be saved on server, and there is more then one million users ), then I read the file, and every 10th frame I update the position and angle of ghost replay.
The problem is that I can’t get smooth movement of ghost airplane even when using Vector3.Lerp.
I think there’s something seriously… wrong here For starters, I think you should not read file every 10th frame.
Instead, I would do something like this (pseudo code)
store inputs or states into a list (time, position, rotation) save this info into a file ONCE (after level completed or such)
…open the file ONCE, before starting the level: read the values into a list,
you can then go through the list on Update (or FixedUpdate), and update ghost object position rotation based on time (I don’t have sample code here, but hopefully you get the idea – try searching the forums for “replay code”)
The code actually works as you described, I read content from file in constructor, FileRead is just name of the class with arrays of positions and angles which I access every frame.
Anyway, I changed the code to make it more clear :
is the “currentReadPosition” actually necessary?
just have:
Vector3.Lerp(transform.position, targetReadPosition, …)
And you can use Update, no need to use FixedUpdate for positioning. So try put your lerp commands inside Update() and see if that helps. Also, remember that lerp 3rd parameter is about “when you reach target”. I think your count % 10 * 0.1 thing is slightly wrong and doesnt help with smoothing. See for example here: http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html