Advertisement

Help w/Collision Detection

Started by September 10, 2000 11:58 AM
2 comments, last by fungame 24 years, 3 months ago
Hey all. I have a 2d game with very fast moving sprites. I want to know if anyone knows of good algorithms, or info atleast, on sprites that cross eachothers path, but their bounding boxes do not overlap during collision dectection cause they moved so much since the last update. This makes the illusion that they passed over the top of eachother when it never happened. Help is appreciated! Thanks
I would suggest installing a timer so you can adjust how far the sprites move each frame. without doing this, it will be different on every computer and you won''t be able to adjust the collision detection.

JoeMont001@aol.com www.polarisoft.n3.net
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Advertisement
If you are going to use each of the corners of the sprites, you could draw ''lines'' from their current and to-be locations, for every sprite, then test to see if the lines intercept each other.

So, if the sprite''s top-left corner is at 100,200 and it will be at 400,800 then you could say the linear equation of the line is:


m = ((y2-y1)/(x2-x1))
yq = m*x + (y1-(m*x1))

(This is off the top of my head, so tell me if my equation is wrong , also it is meant to use boxes only, not per-pixel calcuations, though you could probably through that in as an afterthought)

The take this equation, and test it against the other sprites'' equations, to see if you have collision between them, then you would have to use some form of interpolation to determine where along each line they contacted and make them change direction, and velocities accordingly.

Also, do as Julio said, make a timer, this is a very important step in any physics ruitine, and not all that hard to do.
goto
http://qsoft.cjb.net
tutrials-->dos-->collion detection

i hope it will help you!

This topic is closed to new replies.

Advertisement