Path: chuka.playstation.co.uk!news From: Phil Gooch Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: What to do after a collision has been detected (related to previous post) Date: Tue, 08 Sep 1998 17:07:49 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 51 Message-ID: <35F55655.3D90443B@easynet.co.uk> References: <35F3E1A4.8A7BB2E6@easynet.co.uk> NNTP-Posting-Host: 193.131.140.246 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) Toby Sargeant wrote: > What about doing the colision speculatively? Here's what I'd do: > > * calculate new car position from velocity vector > * if new car position causes a colision: > * use reflection rule (angle of incidence = angle of reflection) > to calculate a new velocity vector. > * apply new velocity vector to position of car to get new position > * if new position also causes a colision: > * must be stuck in a corner. because the position we came > from to get to the curent position must be valid, it must > be valid to use the inverse velocity vector to get back > to the position we were in the frame before last. so: > new velocity vector = -old velocity vector > * update car position from the velocity vector (guaranteed not to cause a > collision) > This seems to make sense. Thanks Toby. I'm also finding that it makes a difference *when* you do your collision detection. Part of my problem might be that I'm currently doing things in this order: 1) Check joypad 2) Update velocity vector based on joypad response 3) Calculate position 4) Check for collision 5) Adjust velocity vector if collision 6) Draw sprite This seemed OK until I realised that 5) could immediately be cancelled out by 2) at the start of the next frame. If I do 1) Calculate position 2) Check for collision 3) Adjust velocity vector if collision 4) Calculate new position 5) Draw sprite 6) Check joypad 7) Update velocity vector based on joypad response then I should be OK. I'll check it out when I next get a chance to switch on my Yaroze. Phil