Path: chuka.playstation.co.uk!news From: James Russell Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: 2d Collision detection Date: Wed, 07 Oct 1998 21:24:08 +0100 Organization: Sony Computer Entertainment Europe Lines: 41 Message-ID: <361BCDE8.D62A075D@scee.sony.co.uk> References: <6vggm5$6uj2@scea> NNTP-Posting-Host: mailgate.scee.sony.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.5b2 [en] (Win95; I) X-Accept-Language: en Slight adjustment to your code - if you detect a collision, then break out of the for loop, it will make it run slightly faster for a large number of objects. Antony Arciuolo wrote: > > Now my problem is I got my guy scooting along at a speed of 5, so collision appears as if > the guy is hitting a force field. Also if I slow down to 4,3,2,1 the force field around the > other object gets smaller. How can I make so that a collision means the borders of the > bounding boxes are touching and will be touching until the position is updated? Ohhh, tricky to do efficiently - basically your problem is your sampling rate, which is once per frame. However, this is not high enough. It is possible that your object could 'speed' right through a wall, simply because the checker would have checked the start position (OK) on one side, then checked the 'final' position (also OK) on the other side. The only way I can see is to increase the sampling rate - that is: for(a = 0; a < obj->currentSpeed; a++) { Check for collision at Obj->x + rcos(angle) * a, Obj->y + rsin(angle) * a; if collision, collided = TRUE; } so you're checking at multiple positions along the (position+velocity) vector. The other way is also O(n) - you'd 'point' the velocity vector, and solve for intersection with that vector. If the coefficient of intersection is < 0, > currentSpeed, or doesn't solve (i.e the vector would never intersect), then there was no collision. This is slightly more complex but is more accurate, and as a bonus you get the exact point of collision. Easy with vectors, bit harder with bounding boxes... Cheers, James -- == James_Russell@scee.sony.co.uk +44 (171) 447-1626 == Developer Support Engineer - Sony Computer Entertainment Europe At the border: "What's in the trunk?" "Oh, nobody!"