Frame interpolation problem with collision response

Started by
3 comments, last by Numsgil 15 years, 10 months ago
Hi, I'm trying to figure out a good representation for object positions/movement in a 2D game. I use a fixed frame-rate for the logic (20fps) and render as fast as I can. What I want to do is interpolate positions between logic frames so that the rendered movements look much smoother than they really are. I've been using a simple interpolation-class that stores a reference position, the timestamp for that position and a direction. Then I simply ask the interpolator where the position is at a given time (linear interpolation). The problem arises when I try to do collision responses. If an object hits a wall between two logic frames (and it often will, I'm doing swept-tests for the movement path between logic frames) it should bounce of that wall. This means that its movement path will not be linear between two frames, but rather a "bent" line. I can't interpolate such a complex path as of now and I'm wondering what a good way to represent movement and position would be? My solution have been to move the object to the intersection point and change its direction. This however results in a noticeable "snapping" to the intersection point. Is it a good idea to use linear between-frame interpolation? If not, what should I look into? Any help would be appreciated, thnx
Advertisement
Can an object collide multiple times in a single logic step? If not, your interpolation class could be like this:

position at start of frame
position at collision
time of collision
position at end of frame

and if there is no collision, you just interpolate to the end of the frame, otherwise you either go from start to collision, or collision to end, depending wether the current time is less or greater than the collision time.
This question has some information that i need answered.

I have my OnPaint Method where i am doing all my render, but how do i setup so i can check every frame as below?

position at start of frame
position at collision
time of collision
position at end of frame
I'm not sure exactly how to implement it, it was more a theoretical method of solving the problem you asked about. The easiest implementation would depend on how you have things set up already.

Also, like I said, it would only work for a single collision per logic step. If your collision algorithm does a loop, moving to the time of each collision and responding until the full frame time has elapsed, then it might not be good enough. But it should still look better than interpolating straight from the start to the end position, since it would at least contact a wall before moving toward the end position.

EDIT: Sorry Meshboy, I thought you were the OP :p
Or maybe you were asking for more info on my idea? I'm not quite sure so I guess I'll leave this post here.
I'm using a custom method I devised that fixes the issue in my own engine (I think it's called a Discrete Event System in literature, but I'm not entirely certain it's the same thing): between collisions, you can interpolate position just fine. I call this an "epoch". ("Event" is the term used in DES literature, I think). You can store an epoch in a variety of ways, but the easiest is to just store it as a starting position and starting velocity.

Each body has an "epoch list", simply a list of epochs with timestamps. The epoch list lets you build a piecewise linear interpolation for the objects' actual motion. To find the position at time T, you first find which epoch time T belongs to, then use that epoch to approximate the position.

You can "collapse" the epoch list after a new logical step is available, and remove epochs from last frame. As an added benefit you can do a reversible time step by storing epochs for longer than a single frame and rewinding all your bodies motions (using their epoch lists) to some arbitrary time t.
[size=2]Darwinbots - [size=2]Artificial life simulation

This topic is closed to new replies.

Advertisement