# hitTest glitch with ball and wall

**URL:** <https://forum.kirupa.com/t/hittest-glitch-with-ball-and-wall/281376>\
**Category:** flash\
**Created:** [February 8, 2009, 5:28pm UTC](https://forum.kirupa.com/t/hittest-glitch-with-ball-and-wall/281376 "2009-02-08T17:28:06Z")\
**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 8, 2009, 5:28pm UTC](https://forum.kirupa.com/t/hittest-glitch-with-ball-and-wall/281376/1 "2009-02-08T17:28:06Z")

</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 within the ball(hero):  
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);  
}  
}

Can anyone help me fix the glitching problem?
