Article View: rec.games.programmer
Article #1118Re: Collision/Detection Routines!!!!!
From: Sam Streeper
Date: Sun, 04 Oct 1992 08:06
Date: Sun, 04 Oct 1992 08:06
37 lines
2422 bytes
2422 bytes
> Could someone please give me some simple collison/detection routines? This discussion was quite good, but it missed a couple of points for reducing the overhead of collision detection (that aren't applicable to all applications...) If things move in a predictable fashion, it may be cheapest to precalculate _when_ a collision will happen, rather than doing it on every iteration (where an iteration may or may not correspond to a single animation frame). This has the additional advantage that you can't iterate "over" a collision (things going through each other between iterations but never colliding at iteration time. Another advantage is that since you know exactly when things collide, you know how they collided rather than trying to figure this out post-collision. As an example, imagine two objects, A and B, moving in straight lines. Rather than comparing positions every frame, you can project A's vector until it collides with B's vector at time T. Knowing this, you can happily animate up to time T without checking for collisions. (In the multi object case, T is the minimum of all collision times.) Note that you must recalculate T any time something interesting happens, like any object's vector changing. Recalculating projected collision times isn't necessarily more expensive than simply calculating current collision statuses, however. Some kinds of games lend themselves to an active collsion list. Objects that are outside they realm of interest (like villains two screens behind the hero) can be removed from the active collision checking list to save cycles, and things entering the realm of interest can be added as needed as part of bringing them to life. Hope these thougts are useful. I might add that the cost of collision detection is insignificant compared to the cost of moving graphics around in virtually every application I have ever seen. If performance is important, your first concern should usually be to minimize the amount of drawing you do. -sam
Technical Details
Message-ID:
<5284@rosie.NeXT.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!rosie!NeXT.comReferences:
<1af3r4INN7fi@usenet.INS.CWRU.Edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!rosie!NeXT.com From: sam_s@NeXT.com (Sam Streeper) Newsgroups: rec.games.programmer Subject: Re: Collision/Detection Routines!!!!! Message-ID: <5284@rosie.NeXT.COM> Date: 4 Oct 92 08:06:20 GMT References: <1af3r4INN7fi@usenet.INS.CWRU.Edu> Sender: ltucker@NeXT.COM Reply-To: sam_s@NeXT.com Lines: 37