Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My game loop uses a fixed time step to do "physics" updates, say every 20 ms. In here I move objects. I draw frames as frequently as possible. I work out a value between 0 and 1 to represent the proportion of the physics tick that is complete and interpolate between the previous and current physics state before drawing. It results in a smoother game assuming the frame rate is higher than the physics update rate.

I am currently doing the collision detection in the physics update routine. I was wondering should it instead take place in the interpolated draw routine where the positions match what the user sees? Collisions can result in explosions by the way.

share|improve this question
add comment

1 Answer 1

I assume you're using an approach similar to what this article describes Fix Your Timestep!. I suggest that you don't mix your physics/collision with rendering; do the collision in update like you are right now. That interpolated state is an approximation simply used for smoother rendering. Even if you check for collision on interpolated state, it will not help with visuals.

Here is an example (partially taken from comments of that article):

Suppose you follow this scheme in each time step of physics engine:

  1. Integrate
  2. Test for collisions
  3. Respond to collisions

Consider a ball bouncing off wall forming V shape path and collision is detected/resolved on second time step:

  1. Ball is before collision, visually ball is at left side of the V path
  2. Ball collides with wall, collision resolved, ball has now bounced off and is on right side of the V

Linearly interpolate between these 2 states and you'll be rendering the ball somewhere in the middle of the V path making the collision path seem flatter. Checking collision at the interpolated state will yield no collision and thus will not help in correcting the visuals. Only way to improve visuals here is to make time steps smaller.

share|improve this answer
    
Assuming 50 per second and 75 frames per second: the interpolated values are more fine grained. Wouldn't that help in producing a better result for collision testing? –  Ciaran Mar 19 '12 at 19:50
    
50 updates per sec and 75 renders per sec? –  XiaoChuan Yu Mar 19 '12 at 19:53
    
Sorry. Yes exactly what I meant. –  Ciaran Mar 19 '12 at 20:09
    
I could wrong but the interpolation is just an approximation and will not yield collisions. Can you specify visible defects that you're experiencing or what motivates you to do this extra collision checking on interpolated state? –  XiaoChuan Yu Mar 19 '12 at 20:32
    
It's not that there are defects, I just want to do it right. My thinking was that the approximated value is what we use for drawing which is what the user sees and therefore is the correct value to use for collisions. –  Ciaran Mar 19 '12 at 20:38
show 7 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.