# Actionscript Help

**URL:** <https://forum.kirupa.com/t/actionscript-help/227241>\
**Category:** Uncategorized\
**Created:** [May 28, 2007, 8:15pm UTC](https://forum.kirupa.com/t/actionscript-help/227241 "2007-05-28T20:15:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robot\_Monkey](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@Robot\_Monkey](https://forum.kirupa.com/u/Robot_Monkey)\
**Post date:** [May 28, 2007, 8:15pm UTC](https://forum.kirupa.com/t/actionscript-help/227241/1 "2007-05-28T20:15:07Z")

</div>

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+radius_Math.sin(x_360/precision);  
spot\_y = \_y-radius_Math.cos(x_360/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((yspeed_yspeed)+(xspeed_xspeed));  
xspeed = speed_Math.cos(bounce\_angle_Math.PI/180)_friction;  
yspeed = (speed_Math.sin(bounce\_angle_Math.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.
