Advertisement

Bounding sphere/circle collision detection and handling of really really fast objects

Started by September 18, 2001 08:12 PM
3 comments, last by Wymsical 23 years, 4 months ago
I''m sure this question has been asked before, but I couldn''t find it in any recent posts. How do I handle collision detection with an object that is moving so fast it would jump past an object or even several objects in one game loop? i''m Using bouding circle, atm, but i know i''m going to be using bounding rect/box later so if i could get a way to fix the problem w/ that now, that would be great. Regards The Wymsical Wyvern
You do tests using cylinders (the height is the distance, radius is the radius) or use parametric equations (x,y,t) over a period of time (those are both the same solution in the end).

[Resist Windows XP''s Invasive Production Activation Technology!]
Advertisement
I had the same problem for a while now and came up with a very simple way to solve it yesterday, let me explain

you have a point where the object is
you find the point where the object will be when the next frame is rendered.
Use the 2 points and create a rectangle, and perform the collision detection with this rectangle (you will have to adjust the size of the rectangle depending on the size of the object).

For circles what you could do (I haven''t actually done this with circles) is again find the 2 points. Find the midpoint of a line between the 2 points, this will be the center of the circle. Then make the radius of the circle, half the length of the line. I think the problem with this is that the circle may end up being too big, and the collision detection will not give nice results.

Digital Radiation
This was discussed on this forum about a month and a half ago; that''s why I referred the poster (Wymsical) here.

The solution is to determine when the object will collide rather than if it has collided. Preliminary tests can be performed to eliminate redundant checks. Check GamaSutra for an article on the raycasting/tracing-based collision detection employed in Red Falcon.
Actually, I''d refer you to the gamasutra article by Miguel Gomez, http://gamasutra.com/features/19991018/Gomez_1.htm

He goes through the whole nine yards about this, including sphere-plane, sphere-sphere, and sphere-box, axis alined box-box collisions. All these tests include the velocity vector, which will eliminate problems of "objects missing each other".

Here''s my own version of this code (mostly taken out of the article)..

bool spheresIntersect(float p1[3], float v1[3], float r1, float p2[3], float v2[3], float r2) {	float p[3];			// relative position	float v[3];			// relative velocity	float vv;			// relative velocity squared	float pp;			// relative position squared	float vp;			// relative velocity times relative position	float r, rr;			// critical radius, critical radius squared	vectorCopy(p, p2);	vectorSubtract(p, p1);	vectorCopy(v, v2);	vectorSubtract(v, v1);	pp = vectorDotProduct(p, p);	vv = vectorDotProduct(v, v);	vp = vectorDotProduct(v, p);	r = r1 + r2;	rr = r * r;	// check if already intersecting		if (pp <= rr)		return true;	// check if there are real roots	if (((vp * vp) - (vv * (pp - rr))) >= 0.0f)		return true;	return false;} 


--bart

--bart

This topic is closed to new replies.

Advertisement