Jump to content
  • Advertisement
Sign in to follow this  
sir_wojciech

Collision Detection Between Frames

This topic is 4918 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.





Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!