Implementing a saved ghost for each level in a game
I'm developing a video game for the iPhone. I want each level to save a "ghost" of the best run, just like in Mario Kart.
I've already implemented it, but I used a brute force approach that stores (x, y, rotation) values each frame (60 per second). Needless to say this is very expensive, especially for a mobile device.
I guess I could store the data less often and interpolate when rendering the ghost, but I'm not 100% sure how to do this an开发者_开发知识库d if it will look good.
Has anyone done this before? How would you implement it? Is there a standard approach?
Linear interpolation is very easy, if that's what you want. But if the objects you want to interpolate can have non-linear trajectories (from ballistic or lateral accelleration effects) the thing gets more complicated.
The simplest approach would be for you to record the initial position for an object and its movement vector (x,y,z speed, as offsets per time unit). You won't have to record it again for that object until it changes its speed and/or its direction. Then you just record the elapsed time, the new position and the new movement vector (theoretically you don't have to record the position again, just the vectors, but I'd recommend doing so to have a check value - after the program is debugged you can discard it). Then to playback you place the object at the original position and, for each time frame, add the movement offset to it until it reaches the time for the next recorded position. And so on.
精彩评论