im building a flash car game where if u hit the sides of the buildings you bounce off
my problem is that sometimes you get stuck in the walls and it doesnt bounce at all
heres my bounce code
heres a copy of the gameCode:public function moveCar(timeDiff:Number) { // get current position var carPos:Point = new Point(gamesprite.car.x, gamesprite.car.y); // calculate change var carAngle:Number = gamesprite.car.rotation; var carAngleRadians:Number = (carAngle/360)*(2.0*Math.PI); var carMove:Number = speed*timeDiff; var dx:Number = Math.cos(carAngleRadians)*carMove; var dy:Number = Math.sin(carAngleRadians)*carMove; // see if car is NOT on the road if (!gamesprite.road.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) { gamesprite.car.y = gamesprite.side.y; gamesprite.car.x = gamesprite.side.x; // see if car is on the side //bounce off if (gamesprite.side.hitTestPoint(gamesprite.car.x, gamesprite.car.y, true)) { gamesprite.y = (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 5 / -1; gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4; speed = 0 - speed * bounce; } } // set new position of car gamesprite.car.x = carPos.x+dx; gamesprite.car.y = carPos.y+dy; }
here
can someone help me out plz
thanks




Reply With Quote