Path: chuka.playstation.co.uk!news From: Alex Herbert Newsgroups: scea.yaroze.beginners,scee.yaroze.freetalk.english Subject: Re: Darco's Newbie Tutorials Date: Tue, 15 Sep 1998 17:50:50 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 38 Message-ID: <35FE9AE9.5F49EFCD@ndirect.co.uk> References: <35FE54E6.85E323A8@bigfoot.com> <35FE6B8E.DB23B00D@ndirect.co.uk> <35FE7411.D55A7BD4@easynet.co.uk> Reply-To: aherbert@ndirect.co.uk NNTP-Posting-Host: dialin0-09.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) Xref: chuka.playstation.co.uk scea.yaroze.beginners:274 scee.yaroze.freetalk.english:2329 Phil Gooch wrote: > Alex Herbert wrote: > > > > > > > Collision detection seems to be a tricky area for the newbies. Not so much > > the detection itself, but what to do when a collision has been detected. > > > > > > That's me, that is. It's funny how you get a mental block about some things. In > my 2D game I knocked out the scrolling algorithm, car physics (acceleration, > braking, reversing, turning, skidding, terrain resistance) in no time, but the > collision stuff just has me stumped. I've got the car's collision rect rotating > correctly with the car (2D matrix transforms), so in principle I can do almost > pixel perfect collisions, but my collision routine just won't do the business > (car sticks to boundary, car gets stuck in a collision loop, back and forth, > car drives over boundary etc). > > Phil Try undoing the movement which caused the collision, and these problems usually go away. Maybe I should explain that better. For a 2D example, lets assume you have the co-ords of the object (x and y) and it's velocities (vx and vy). Now, if each frame you are adding vx to x, and vy to y, then as soon as you detect a collision, you could subtract vx from x and, vy from y. This effectively means that the collision never happened, and the problems you are talking about don't happen. (Make sure you do this before your matrix transforms etc.) It's not necessarily the best way to do things, but it is a simple fix which I've used numerous times in the past. Herbs