Path: chuka.playstation.co.uk!news From: Alex Herbert Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: 2d Collision detection Date: Fri, 09 Oct 1998 15:36:58 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 66 Message-ID: <361E1F8A.DA65D1D6@ndirect.co.uk> References: <6vggm5$6uj2@scea> Reply-To: aherbert@ndirect.co.uk NNTP-Posting-Host: th-usr00-39.ndirect.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) Antony Arciuolo wrote: > I am using bounding box collision detection something to the effect of the > code listed below. > 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? > > void WOBJECT_Update(WOBJECT *obj) > { > short degrees, i; > WOBJECT *obj2; > > // Handle position > > obj->oldx = obj->x; > obj->oldy = obj->y; > > if (obj->attribute & WOBJECT_IS_MOVEABLE) > { > degrees = 360 - IPART(obj->currentOrientation); > > obj->x += (obj->currentSpeed * LUCos(degrees)); > obj->y -= (obj->currentSpeed * LUSin(degrees)); > > for (i = 0; i < WOBJECT_ALL_COLLISION_OBJECTS; i++) > { > obj2 = &gAllWorldObjects[i]; > > if (obj != obj2 && WOBJECT_ThereIsACollision(obj, obj2)) > { > obj->x = obj->oldx; > obj->y = obj->oldy; > } > } > } // if should move this object > } Ok. What's happening is you are only allowing an object to move if it won't collide, right? This is why you're getting the force field effect. The motion is stopping before the object collides. Here's what you could do to stop this happening: You tried to move at speed 5, but a collision has been detected. So, try and move at speed 4. If a collision is still detected then try speed 3, etc etc. Get that? This will mean that the object will move until it's just touching the 2nd object. BTW. If your sprites are square (or nearly square), then I'd favour bounding circles rather than boxes when using the angle/speed type movement. If you're interested in how to do this very fast and efficiently, let us know and I'll explain. It can also help with the above problem. Herbs