Path: chuka.playstation.co.uk!news From: Phil Gooch Newsgroups: scee.yaroze.programming.2d_graphics Subject: What to do after a collision has been detected (related to previous post) Date: Mon, 07 Sep 1998 14:37:40 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 58 Message-ID: <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) OK, so I've detected a collision of a sprite with the terrain of my 'road'. What I have done is put all the allowable 'squares' you can be on into one texture page (identified as ROAD) and everything else (trees, grass, roadside edge etc) into another texture page (identified as ROADSIDE). My array data contains info for which texture page the square is read from so I can do (pseudo-code) if ( (mapData[car.mapY][car.mapX] & TPAGE_ID) == ROADSIDE) // the car is on a square from the ROADSIDE texture page, so you have collided with something // bounce car off it car.veloc.x = -car.veloc.x; car.veloc.y = -car.veloc.y; But this 'bouncing off' is causing me problems, because it is possible that the car either gets bounced back onto another square that will register a collision, or be still partly on the collision square after being bounced (as the car's velocity is being damped by friction on every frame as well), causing the car to bounce backwards and forwards ad infinitum. So, to get round this, I have raised a flag to say: 'if you have detected a collision, don't detect any more collisions until you are on a non-colliding square', e.g. if ( (mapData[car.mapY][car.mapX] & TPAGE_ID) == ROADSIDE) // the car is on a square from the ROADSIDE texture page, so you have collided with something // bounce car off it if not already 'colliding' if (car.status.collide != terrainCollide) { car.veloc.x = -car.veloc.x; car.veloc.y = -car.veloc.y; car.status.collide = terrainCollide; // now register the collision so you don't bounce straight back onto // collision square again } else car.status.collide == idle; This prevents the car juddering backwards and forwards that occurs in certain circumstances, but causes another problem: each collision is only registered once, until the car is back on a safe square, so it is possible to drive very slowly towards a terrain obstacle, bounce back slowly but still be on the same collision square, and then move forward and drive over it (because the bounce only happens the first time the collision is detected) Am I a bit thick or what? I can't seem to find a way out of this one! Any insight much appreciated. Cheers Phil