1

After experimenting a little with variable time steps, I switched to using a fixed time step to update my game objects independently of the current framerate. When things are being rendered, I interpolate each object's position, rotation and so on between the last two states.

However, what do I do the first time an object is being rendered? There is no previous state I can use, since the object has just been created with its initial state.

user1925315
  • 67
  • 1
  • 5

2 Answers2

1

You could run one extra update step in the background before rendering anything, so that you'll always have two states available to interpolate between. Or just make the "initial previous state" a copy of the initial state.

It doesn't really matter much what you do, since everything will be fixed anyway after the first real state update, which will happen a small fraction of a second after the game begins — too soon for the player to really notice.

Edit: For objects created during the game, you could always extrapolate their position backwards to get an approximate previous position. This may look better than just having the object sit still (or be invisible) for one tick. The extrapolation still doesn't have to be very accurate, since it will only affect the first tick of the object's movement.

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
  • If all objects would be created at the beginning of the game, that would be right. But since objects may be created anytime during the game, this short freeze will occur once on every object. For example, a bullet may be instantiated. It would just sit there for an entire tick and start moving on the next tick. – user1925315 Dec 25 '12 at 15:29
  • Updating the object after its creation should work though. But what if this update requires other objects to be updates as well? – user1925315 Dec 25 '12 at 15:31
  • Good point. If you know the object's initial velocity, you could always extrapolate its position backwards (not necessarily with a full reverse physics update, but just basic linear extrapolation) to get an approximate previous position. It still won't matter much, since one tick is a pretty short time. – Ilmari Karonen Dec 25 '12 at 15:36
-2

Use away3D 4... It uses stage3D, opensource, and very useful, and easy to use!

Lajos Viktor
  • 148
  • 7
  • 1
    Would you mind describing exactly how your suggestion would help the OP solve their problem? Or are you just randomly spamming? – Ilmari Karonen Dec 25 '12 at 15:22