# How can I predict player-to-projectile collisions in Box2D?

I'm making a real time shooting game with Box2D as the physics engine. The gameplay is mostly about trajectory, like Angry Birds. I want to make a slow motion effect and move camera to the player when he's killed, but the effect should start when the stone is still in the air, before the collision actually happens.

The magnitude of damage is only calculated at collision, based on impulse. Because it's a real-time game, the player must be able to move their character's physics body without lag.

How can I predict their death? Is it even possible? I could raycast, but what if another object moves to block its path?

• Theoretical note: The future of non-deterministic systems is by definition unpredictable. See Schrödinger's cat, mentally replacing "cat" with "player character".
– Anko
Commented Jun 30, 2014 at 20:46
• @Anko very interesting idea! I've never tried that. But the player can still move so where he go or how far he go is not predictable. Yet I know the player's move speed so when the stone is close enough, I know it won't miss... Commented Jun 30, 2014 at 20:48
• (1/2) IMO it would be much more interesting if you used a raycast to see if a collision has a decent chance of occurring, then start the camera zoom and slow the game down. For every frame, re-do the ray cast to see if the stone is still on a collision course. If the stone is intercepted, the camera should just zoom back to its normal state, but for every frame the collision is still likely, zoom the camera a little more. Commented Jul 1, 2014 at 14:26
• (2/2) This will kill two birds with one stone (word play not intended): you won't need to do any 'looking into the future', and the players will experience the thrill of near-misses as well as direct (or grazing) hits. In fact, I could argue that your effects will become boring if the player knows that, every time the camera zooms in and the game slows down, he's doomed. He will want to skip the 'animation' immediately and try again. But if there's a chance he can evade the stone, you can bet he will be biting his nails waiting to see the outcome. Commented Jul 1, 2014 at 14:32
• (1/2)@NauticalMile hey, that's a very good idea too!! I'm afraid it may not directly apply to my game because the player is hit too often, so zooming in and slow motion may interrupt the on-going game too much. Commented Jul 1, 2014 at 19:29