I'm using velocity to move my character, I just add/subtract 0.4f and then update the players position in the update loop.

I was wondering, when would be the best place to check for collision? Do I go ahead move the player, and then if I colliding push him out of the wall until there's no collision? Or do I check collision as soon as the key is pressed, and if there is - somehow find the distance and move the player?

My problem is that my game is tile based, but the world is constantly rotating around the player - I have a function that returns a list of objects of each block that the player is colliding with, and I'm having trouble separating wall collisions with floor collisions


1 Answer 1


Both. As a body moves, there is a volume that it covers over a period of time. Imagine taking a sphere that moves along a line over a small period of time. The shape that it will cover (or "sweep") over this time is a capsule.

When you run your simulation over a time step, calculate these volumes and use those in your intersection testing. This will also solve the "Bullet through Paper" problem: if you have a very fast moving object move through a very thin object with a large enough time step, you won't detect the collision.

In your situation, there are lots of static objects; you can make an optimization to avoid calculating the swept volumes for these.

Interestingly, I just answered another question that is relevant, and will probably help you with other problems you're likely to encounter:

How to resolve penetration of two colliding bodies

  • \$\begingroup\$ I've looked at "sweep" tests before, but I couldn't for my life figure out an efficient way to create that swept mesh (or swept polygon in 2D games) that the swept body creates when moving in two timesteps. Can you suggest articles or something that I should take a look at? \$\endgroup\$
    – TravisG
    Jan 13, 2012 at 18:57
  • \$\begingroup\$ You're not trying to create a mesh. You want to use a bounding sphere for this test, because the math is trivial. gamasutra.com/view/feature/3383/… looks like it explains the technique. \$\endgroup\$
    – notlesh
    Jan 13, 2012 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .