Collision Detection Between Frames

Started by
7 comments, last by Funkapotamus 18 years, 10 months ago
Has anyone any idea how to detect collision between frames? Example: In the first frame the object was before the wall. And in the second frame it's behind the wall. And no collision occured... (at least for my game) I'd like to solve this problem for my 2D game (in java)... Thanks in advance!
Advertisement
In the field of collision detection, this is known as the "tunneling problem". There's a few solutions.

1. Collide not only against the end position of the moving object, but also against n intermediate copies in a straight line from beginning to end. This isn't really a complete solution, though, since sufficiently small moving objects can still tunnel through sufficiently thin walls.

2. Sweep the object from beginning to end, and collide with the resultant volume. Example: assume a circle, parallel to the ground, which moves up one foot during the timestep. The resultant swept volume would be a cylinder, with the cross-section of the circle and a height of one foot. This is tricky to calculate for certain types of solids.

3. Compute the "Minkowski sum" of the particle and the wall, and collide it against a single line segment representing the particle's trajectory for that timestep. This is a relatively advanced technique, but one that's not too hard to implement once you really understand it.
That was a really really useful reply. I'll try all the things you mentioned.
Thanks!
I ran into this same problem in my SnakeJump game where I had a ball bouncing on platforms at different speeds.

I basically used a really cheap method -- I used an "epsilon value" and extended the width of the platform by that value. The value is based on the speed of the ball...so if the ball is moving at 10 pixels/frame, each platform is an extra virtual 5 pixels tall on the top and bottom.

It works pretty well, but only because the game runs quickly, so people don't notice that the ball is bouncing a couple of pixels about the platform.
It won't work perfectly for my game. It's a tile-map game. Well but it's worth trying. Thanks for your reply.
Also a question about 2d colision:

I have a map (a static enviroment image) where some pixels are blocking (like walls, ground...). I have a character that I want to move around. And I also have some dynamic objects (like elevator platforms) that can support the player.
I am thinking about the colision solving in this situation and I want to know your opinion too.
What is the correct order to perform colision tests and solve them?

1. Should I first try to adjust player position from the user input (walk left for ex.), test colision, and place it safe. Then try to test platforms that may affect (rise) player and solve that too?

2. Should I try to move the player into the desired position and, at the end, see if it's inside a colision and I bring it back in the previous position ?

3. Is it better to test dynamic objects first and then the static room ? Or is it better to test them both at the same time ?

My player do not bounce from walls and do not fall at any angle possibl.
It's only moves are: stand (idle), left, right, jump (up, up-left, up-right), fell (down, down-left, down-right)

If I wasn't very clear what I want... just tell me how would you solve collision in this case.
Thanks!
I use option 2 - I move the object, test, and move it back if necessary. Sometimes you won't move it all the way back but will just clip the movement accordingly. I don't think it matters what you test first.
I agree with Kylotan. Idealy however, I'd group environmental things with the elevator itself, as it functions pretty much the same as moveable terrain. Your environment image could be a dynamic one. Take this with a grain of salt however, as I don't know how you've written things.

Referring back to the original post:
It might be useful to find the minimum velocity at which an entity will begin passing through invalid objects. Once the entity has passed this speed, only then would you have to do extra math. Typically, the instances where missed collisions occur are exceptions to the rule. It would be benifitial speed wise to treat them as such rather than to add a global calculation to all your entities.





Forgot to log in- The above post was me.

I should clarify. "Benifitial speed wise" refers to the speed of your program.
Less heavy calculations = faster game!

This topic is closed to new replies.

Advertisement