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.

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

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
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? –  TravisG Jan 13 '12 at 18:57
    
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. –  stephelton Jan 13 '12 at 19:57
add comment

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.