File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Game Development and the fly likes Interpolation using Object's old and current positions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Interpolation using Object Watch "Interpolation using Object New topic

Interpolation using Object's old and current positions

Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 41
Hi All

I'm attempting to smooth out the animation of my sprites using interpolation and am have a lot of problems.

I've managed to get some success using this method of applying the interpolation during my render call:

When the sprite is moving, it is almost perfectly smooth (it's like a 95% improvement on no interpolation) but when the sprite is static, the interpolation is still applied and the sprite therefore has a 'wobbling' effect. (It also play havoc with my collision detection but that's for another day!)

Now, I've come across another method, which seems more sensible. This method necessitates us saving the sprites previous position so the following calculation can be made in the render call:

Now, this doesn't wobble when the sprite is static, because the difference between the current and old positions would be 0. However, when the sprite moves, there is no improvement in the choppiness. It also seems to behave better with regards to collision (but this is probably because it's not actually interpolating correctly!)

Oh, and this is my game loop showing how I work out my interpolation value:

I would be very grateful if somone could tell me why the 2nd method doesn't seem to be doing anything.... is the calculation wrong? How do I go about interpolating between an object's previous and current positions?!

Thanks all!

I agree. Here's the link:
subject: Interpolation using Object's old and current positions
jQuery in Action, 3rd edition