# hitTest glitch with ball and several walls

**URL:** <https://forum.kirupa.com/t/hittest-glitch-with-ball-and-several-walls/281411>\
**Category:** programming\
**Created:** [February 9, 2009, 3:48am UTC](https://forum.kirupa.com/t/hittest-glitch-with-ball-and-several-walls/281411 "2009-02-09T03:48:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xZeRo23](https://avatars.discourse-cdn.com/v4/letter/x/91b2a8/32.png) [@xZeRo23](https://forum.kirupa.com/u/xZeRo23)\
**Post date:** [February 9, 2009, 3:48am UTC](https://forum.kirupa.com/t/hittest-glitch-with-ball-and-several-walls/281411/1 "2009-02-09T03:48:35Z")

</div>

I’m making a game where the ball bounces off several walls to get to its destination: the portal. When the ball reaches a high speed it glitches through most of the walls.

Here is my scene for the 3rd level of my game where the most glitches occur (attached file)  
In the picture there lists all the variables i put in the objects. You will also notice that I put a “Stuck” button since there were many glitches.

Here is my code:  
onClipEvent (load) {  
power = 1;  
yspeed = 0;  
xspeed = 0;  
friction = 1;  
gravity = 0.5;  
thrust = 1.6;  
}  
onClipEvent (enterFrame) {  
if (Key.isDown(Key.LEFT)) {  
xspeed -= power;  
}  
if (Key.isDown(Key.RIGHT)) {  
xspeed += power;  
}  
if (Key.isDown(Key.DOWN)) {  
yspeed += power\*thrust;  
}  
xspeed _= friction;  
yspeed += gravity;  
\_y += yspeed;  
\_x += xspeed;  
if (\_root.wall2.hitTest(\_x-(this.\_width/2), \_y, true) or \_root.wall2.hitTest(\_x+(this.\_width/2), \_y, true)) {  
xspeed = -1;  
}  
if (\_root.wall1.hitTest(\_x, \_y-(this.\_height/2), true) or \_root.wall1.hitTest(\_x, \_y+(this.\_height/2), true)) {  
yspeed = -1;  
}  
if (\_root.bounce.hitTest(\_root.hero)){  
\_root.hero.yspeed=-1;  
}  
if (\_root.bounce1.hitTest(\_root.hero)){  
\_root.hero.yspeed=-1;  
}  
if (\_root.bounce2.hitTest(\_root.hero)){  
\_root.hero.yspeed_=-1;  
}

if (\_root.portal.hitTest(\_x, \_y, true)) {  
\_root.gotoAndStop(4);  
}  
}
