Groups | Blog | Home
all groups > flash actionscript > april 2007 >

flash actionscript : help with bounce script?


jamiemac2005
4/1/2007 6:09:50 PM
Okay, so i have written a small script (alot like those birds-eye car racing
games that pretty much just handles a box as a car is the same way as the games
do. but theres a problem, when the car hits a wall i multiply the acceleration
value by -1 and the car bounces back fine, but if the box goes towards the wall
at a dodgey angle sometimes it gets stuck on the wall(i use gskinners collision
detection script/class which can be found by googleing the general keywords i
just specified ), here's my script, mabye someone's used stuff like this and
has debugged it already enough to know a solution?

import com.gskinner.sprites.CollisionDetection;


var walls:MovieClip =
_root.attachMovie("walls_mc","walls1_mc",_root.getNextHighestDepth());
var car:MovieClip =
_root.attachMovie("car_mc","car1_mc",_root.getNextHighestDepth());
var accel:Number = 0;
var angle = 0;
car._x=Stage.width/2;
car._y=Stage,height/2;
car.onEnterFrame = function(){
var collision1 = CollisionDetection.checkForCollision(car1_mc. walls1_mc, 120);
if(collision1){
accel*=-1;
} else {

some general if key.isdown statements that add to the variable accel and the
variable angle.

}
var angleRadians = angle*Math.PI/180
var adjacent = Math.cos(angleRadians)*accel;
var opposite = Math.sin(angleRadians)*accel;
this._x+=adjacent;
this._y+=opposite;
this._rotation = angle;
}

you'll have to imagine that walls_mc is a movie clip containing 4 walls that
go from (50, 50) to (500,350).
and that my stage is the general 550*400 size. also the car_mc movie clip is a
rectangle that is 85*25

the thing is if a corner of the car hits the wall it bounces still but then if
the accel value was not high enough it stays caught on the wall...

anyone experienced this before?
kglad
4/1/2007 9:13:42 PM
jamiemac2005
4/2/2007 12:00:00 AM
kglad
4/2/2007 2:40:34 PM
AddThis Social Bookmark Button