# I need help with hitTests!

**URL:** <https://forum.kirupa.com/t/i-need-help-with-hittests/192356>\
**Category:** Uncategorized\
**Created:** [June 28, 2006, 1:51am UTC](https://forum.kirupa.com/t/i-need-help-with-hittests/192356 "2006-06-28T01:51:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![woad](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@woad](https://forum.kirupa.com/u/woad)\
**Post date:** [June 28, 2006, 1:51am UTC](https://forum.kirupa.com/t/i-need-help-with-hittests/192356/1 "2006-06-28T01:51:31Z")

</div>

I’ve been going crazy trying to figure out whats wrong :h: .

barrier.onEnterFrame = function() {  
with (\_root.tank) {  
if (Key.isDown(Key.DOWN)) {  
\_y += 1;  
}  
if (Key.isDown(Key.UP)) {  
\_y -= 1;  
}  
if (Key.isDown(Key.LEFT)) {  
\_x -= 1;  
}  
if (Key.isDown(Key.RIGHT)) {  
\_x += 1;  
}  
if (this.hitTest(getBounds(\_root).xMax, \_y, true)) {  
\_x -= 1;  
}  
if (this.hitTest(getBounds(\_root).xMin, \_y, true)) {  
\_x += 1;  
}  
if (this.hitTest(\_x, getBounds(\_root).yMax, true)) {  
\_y -= 1;  
}  
if (this.hitTest(\_x, getBounds(\_root).yMin, true)) {  
\_y += 1;  
}  
}  
};

There’s the code. I’ll attach the fla too. It just doesn’t work right, like if you go diagonal you can go through the wall. Or if you come down from the top of the wall you go through it, sometimes even the bottom wall.

Could someone help me, point me in the right direction with links or source, or maybe even remake it in a better way? PLease?
