if i only hit the first coin the output box says
removing
collision!! , coins ==1
removing
collision!! , coins ==2
removing
collision!! , coins ==3
removing
collision!! , coins ==4
removing
collision!! , coins ==5>
the code for the detection and the rest off the ball movie clip is
onClipEvent (load) {
turn = 0;
coins = 0;
yspeed = 0;
xspeed = 0;
gravity = 0.2;
radius = 5;
friction = 0.90;
precision = 360;
bounces = 0;
}
onClipEvent (enterFrame) {
if (root.go == true) {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x<precision; x++) {
spotx = x+radius*Math.sin(x*360/precision);
spoty = y-radius*Math.cos(x*360/precision);
if (root.terrain.hitTest(spotx, spoty, true)) {
collisions++;
sum_x = spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
root.last_hit._x = oldx;
root.last_hit._y = oldy;
bounces;
_root.collisions.text = "Bounces: "bounces;
ball_dir = Math.atan(yspeed/(xspeed*-1))/(Math.PI/180);
if ((xspeed*-1)<0) {
ball_dir = 180;
}
if ((xspeed*-1)>=0 && yspeed<0) {
ball_dir += 360;
}
spot_x = sum_x/collisions;
spot_y = sum_y/collisions;
x_cat = spot_x-x;
y_cat = spot_y-y;
ball_coll = Math.atan(y_cat/x_cat)/(Math.PI/180);
if (x_cat<0) {
ball_coll += 180;
}
if (x_cat>=0 && y_cat<0) {
ball_coll += 360;
}
ground_rotation = ball_coll-90;
if (ground_rotation<0) {
ground_rotation += 180;
}
bounce_angle = 180-ball_dir-2*(ground_rotation);
if (bounceangle<0) {
bounceangle += 360;
}
speed = Math.sqrt((yspeed*yspeed)(xspeed*xspeed));
xspeed = speed*Math.cos(bounce_angle*Math.PI/180)friction;
yspeed = (speedMath.sin(bounce_angle*Math.PI/180))-1friction;
x = oldx;
y = old_y;
}
else{
oldx = x;
oldy = _y;
}
_y = _y+yspeed;
_x = x+xspeed;
}
if (root.coin.hitTest(spotx, spoty, true)) {
root.coin.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”coins)
}
if (root.coin2.hitTest(spot_x, spoty, true)) {
root.coin2.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”coins)
}
if (root.coin3.hitTest(spot_x, spoty, true)) {
root.coin3.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”coins)
}
if (root.coin4.hitTest(spot_x, spoty, true)) {
root.coin4.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”coins)
}
if (root.coin5.hitTest(spot_x, spoty, true)) {
root.coin5.visible = false;
trace(“removing”)
coins =1;
trace(“collision!! , coins ==”coins)
}
if (coins == 5) {_root.gotoAndPlay(1)
}
}