Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

Collision/TimeBased Movement Problem

This topic is 4878 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

I did some search of old posts and didnt come up with anything (dont flame me if you do ok) anyway I am using a bounding box collision detection system but am also using timebased movement, this creats a problem because when there is a fram spike or any frame time diffrence greater then 1 sec then the moving object pretty much smashes through the bounding box of the other object. How can i prevent this ? thx =)

Share this post


Link to post
Share on other sites
Advertisement
Easy. Once it smashes through, reset it's position to where it would have originally hit. I do that with my jump-n-run. The objects regularly go past the collision point, my code just moves it back to where it belongs when that happens.

***Edit***

Oh wait, you're saying it completely jumps past the bounding box, eh? I'd say implement a fixed frame-rate. As long as your second long lags aren't located in the logic code, you'd be fine. Set your game logic to loop 60 times a second... thats once every 16.66 milliseconds... Each frame find out how long it's been since the last frame. If it's been 500 milliseconds, loop through the logic 30 times. After you've looped through your logic, render the frame once for all of that, then go back and do it again.

This way Your logic isn't bound up by how long it takes to draw a scene.

I implemented my system based on this article.
Fix Your Timestep

Share this post


Link to post
Share on other sites
You're going to have to switch to checking if the paths of the objects intersect, which is a tough thing to do.

Share this post


Link to post
Share on other sites
Would you calculate the path using the position of the object in the previous frame and the position of the object in the current frame? Just curious. I've never even thought of using paths to do collision detection...

Share this post


Link to post
Share on other sites
Quote:
Would you calculate the path using the position of the object in the previous frame and the position of the object in the current frame?
There are different ways you can handle the details, but that's generally how you do it.

Collision detection with moving objects can range from pretty easy to quite difficult, depending on what sort of objects you're dealing with. Circles and spheres require solving a simple quadratic and are pretty easy. Bounding boxes in 2d and 3d can be swept against each other using the separating axis test, although the test is more robust in 2d than in 3d. It works for both AABBs and OBBs, and as usual the AABB test is simpler.

Sweeping spheres against boxes is a little more complicated, but doable. There are also more general algorithms for convex objects, but they are much more difficult to implement than the above.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
You can also step the collision system at smaller fixed intervals instead of one big jump.


There we go. Stated much more succinctly than I managed to in my post. (I think I tend to ramble) [wink] It all started back in Nineteen aught Two. Back then we wore onions on our belt, which was the style at the time. There were only dikkity-two states at the time (we had to say dikkity, because the keiser stole our word for twenty). Anyways the trick to *trails off into the background*...

Share this post


Link to post
Share on other sites
ok this solution works out great because i only have one function that is my game loop so all i need to do is

for(int i = 0; i < GFX_H->Frame_Time; i++)
{
//GAME LOOP
}

i also have capped the possible value for Frame_Time to 60 so that if you have a real bad lag spike your comp doesnt try to play catch up for the next 5 min but its still kind of choppy, is there anything else i can do to smooth it out?

**EDIT**

actually i figured out a way to smooth it out even more, i have a bool that i set to true when i am lagging (thats the name of the variable) then i test this variable in my game loop, if(lagging) update status of sprites and collisions but dont draw. if(!lagging) then do the full game loop

I added in a frame rate log and my time between frames is about 20ms which is pretty good and just happens to be my lag threshold (guess that means it works =p)

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!