# Rotating ball

**URL:** <https://forum.kirupa.com/t/rotating-ball/196679>\
**Category:** Uncategorized\
**Created:** [August 10, 2006, 6:39am UTC](https://forum.kirupa.com/t/rotating-ball/196679 "2006-08-10T06:39:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SquishyB](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SquishyB](https://forum.kirupa.com/u/SquishyB)\
**Post date:** [August 10, 2006, 6:39am UTC](https://forum.kirupa.com/t/rotating-ball/196679/1 "2006-08-10T06:39:52Z")

</div>

Hi guys,  
I have the following script, and it works fine, i just was wondering if there is a way to get the ball rolling at all? to make it rotate when it bounces around? It is an image of a soccer ball so it would be fantastic to get it working!  
Cheers!  
-SquishyB

onClipEvent (load) {  
\_x = 43;  
\_y = 17;  
xspeed = Math.random()_60;  
yspeed = Math.random()60;  
rightedge = 662;  
leftedge = 0;  
topedge = 0;  
bottomedge = 156;  
gravity = 2;  
drag = 0.98;  
bounce = 0.9;  
}  
onClipEvent (enterFrame) {  
if (!dragging) {  
\_x = \_x+xspeed;  
\_y = \_y+yspeed;  
//Checks if the ball touches the central shape  
if (\_parent.shape.hitTest(this.\_x, this.\_y, true)) {  
//Checks if the ball touches the shape from the right  
if (!\_parent.shape.hitTest(this.\_x-(this.\_width/2), this.\_y, true)) {  
xspeed = -xspeedbounce;  
while (\_parent.shape.hitTest(this.\_x+(this.\_width/2), this.\_y, true)) {  
this.\_x = this.\_x-1;  
}  
}  
//Checks if the ball touches the shape from the left  
if (!\_parent.shape.hitTest(this.\_x+(this.\_width/2), this.\_y, true)) {  
xspeed = -xspeed_bounce;  
while (\_parent.shape.hitTest(this.\_x-(this.\_width/2), this.\_y, true)) {  
this.\_x = this.\_x+1;  
}  
}  
//Checks if the ball touches the shape from the bottom  
if (!\_parent.shape.hitTest(this.\_x, this.\_y+(this.\_height/2), true)) {  
yspeed = -yspeed_bounce;  
while (\_parent.shape.hitTest(this.\_x, this.\_y-(this.\_height/2), true)) {  
this.\_y = this.\_y+1;  
}  
}  
//Checks if the ball touches the shape from above  
if (!\_parent.shape.hitTest(this.\_x, this.\_y-(this.\_height/2), true)) {  
yspeed = -yspeed_bounce;  
while (\_parent.shape.hitTest(this.\_x, this.\_y+(this.\_height/2), true)) {  
this.\_y = this.\_y-1;  
}  
/_if (yspeed\<2) {  
yspeed = 0;  
gravity = 0;  
}  
if (gravity == 0 && \_parent.shape.hitTest(this.\_x, this.\_y+this.\_height, true)) {  
gravity = 2;  
trace(“true”);  
}_/  
}  
} else {  
//Checks if the ball touches the right wall  
if (\_x+\_width/2\>rightedge) {  
\_x = rightedge-\_width/2;  
xspeed = -xspeed_bounce;  
}  
//Checks if the ball touches the left wall  
if (\_x-\_width/2\<leftedge) {  
\_x = leftedge+\_width/2;  
xspeed = -xspeed_bounce;  
}  
//Checks if the ball touches the bottom wall  
if (\_y+\_width/2\>bottomedge) {  
\_y = bottomedge-\_width/2;  
yspeed = -yspeed_bounce;  
}  
//Checks if the ball touches the top wall  
if (\_y-\_width/2\<topedge) {  
\_y = topedge+\_width/2;  
yspeed = -yspeed_bounce;  
}  
}  
yspeed = yspeed_drag+gravity;  
xspeed = xspeed_drag;  
} else {  
xspeed = \_x-oldx;  
yspeed = \_y-oldy;  
oldx = \_x;  
oldy = \_y;  
gravity = 1;  
}  
}
