I’m making this new game, and I’m having a lot of trouble with the actionscript in it. You see, there’s this ball, and you have to draw a path to lead it to the exit and the next level. I can’t seem to make it so that when the ball collides with the exit, it goes and stops at the next frame.
Here’s the script that’s located in the ball:
onClipEvent (load) {
yspeed = 0;
xspeed = 0;
gravity = 0.2;
radius = 20;
friction = 0.90;
precision = 360;
bounces = 0;
}
onClipEvent (enterFrame) {
if (_root.go == true) {
if (_root.exit.hitTest(_x, _y, true)) {
xspeed = 0;
yspeed = 0;
} else {
collisions = 0;
sum_x = 0;
sum_y = 0;
yspeed = yspeed+gravity;
for (x=1; x<precision; x++) {
spot_x = _x+radiusMath.sin(x360/precision);
spot_y = _y-radiusMath.cos(x360/precision);
if (_root.terrain.hitTest(spot_x, spot_y, true)) {
collisions++;
sum_x += spot_x;
sum_y += spot_y;
}
}
if (collisions>0) {
_root.last_hit._x = old_x;
_root.last_hit._y = old_y;
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 (bounce_angle<0) {
bounce_angle += 360;
}
speed = Math.sqrt((yspeedyspeed)+(xspeedxspeed));
xspeed = speedMath.cos(bounce_angleMath.PI/180)friction;
yspeed = (speedMath.sin(bounce_angleMath.PI/180))-1*friction;
_x = old_x;
_y = old_y;
} else {
old_x = _x;
old_y = _y;
}
_y = _y+yspeed;
_x = _x+xspeed;
_rotation += xspeed;
}
}
}
If anybody can solve it, I’ll give you credit in the credits thing.