Fast movement collisions

BlitzMax Forums/BlitzMax Programming/Fast movement collisions

Robert Cummings(Posted 2005) [#1]
Hi there...

if I have rect to rect collision or circle to circle collision, and am using delta timing, how do I...

detect that the circles overlap regardless of speed
find the final position of the circle so that it doesn't overlap but just touches the circle it collides for?

Basically I'd like to fire it out at 100 pixels a second but collide instead of jumping over. I think rect to rect would be a lot harder, so for now I'm asking for code or tips on circle to circle :)

The only other alternative is to run my game logic loop really high to create small movement steps...


xlsior(Posted 2005) [#2]
And actual collision should be pretty standard, but you're mainly interested in detecting that 'should' have hit and not jump over?

Since you should know the speed of whatever object you are firing, you can recall its previous position as well (or even remember it, if recalculating it would be too intensive).
If the target object is located somewhere in the direct path between the current position of your bullet object and its previous position, you must have jumped across it and should have hit.

Are you looking for 'pixel perfect' collisions, or would a geometric shape bounding box around your target suffice? The latter would be a lot easier to check for..

If it's a non-geometric shape, you could create a mask of a line between the previous and current position and see if that asked object has a collision with the target object, but that may be a tad slower than trying to do the math and see if a line touched a bounding box for the target.


Robert Cummings(Posted 2005) [#3]
Just basic circles and rects.

I think the easiest way is to just multi sample the collisions by moving in smaller steps and testing more frequently.

So if it's size is 32x32 and I'm moving more than 16 pixels per loop, I'll need to double the samples so it moves 8 pixels per loop with collisions twice.

It's double the maths but the maths aren't too intensive. Although thats 100 collision checks instead of 50 right there.


Fetze(Posted 2005) [#4]
In theory, would the same loop-thingy be too slow if I did it with pixelperfect Collisionchecks?


tonyg(Posted 2005) [#5]
Depends on the number of collision checks.
This might help with multiple tests...
shifted grid


AntonyWells(Posted 2005) [#6]
In vivid.2d.net I use linepicks. Basically do four line intersection tests. Each being the movement of the smallest image checked against the bounding box of the bigger image.


Sweenie(Posted 2005) [#7]
I love this tutorial on the subject.
It got lot of pictures... in color
It also got interactive applets. :)

http://www.harveycartel.org/metanet/tutorials/tutorialA.html


Robert Cummings(Posted 2005) [#8]
thanks guys, interesting thoughts... ultimately I'm going to cop out and sample it multiple times though :)


Will(Posted 2005) [#9]
Wait, don't cop out: this is easy - do a check at their final locations to see if they intersect, and then do a line on line collision check where you check the edges of their paths against each other.




Will(Posted 2005) [#10]
whoops, i could be more explicit - just check each yellow line against each gray line - whatever intersection is closest to the original position is roughly where they collided. The advantage of this over sampling is you can use the same standard collision system for really fast objects, like bullets. I believe this is how Doom 3 collisions work as well - bullets aren't just ray casts, they are actual 3D objects with really high velocities, and the stencil buffer is used to draw out their trajectories and do collision checks on them. Just an interesting side note ;)


Robert Cummings(Posted 2005) [#11]
Hey cool trick! thanks :)


Shagwana(Posted 2005) [#12]
How would that work for say two squares that are rotating around there center?


Dreamora(Posted 2005) [#13]
Circle collision with half diameter as radius for the "fast check" and a more precise if fast check gave a possible collision