# You can help me in hitTest ,so please enter

**URL:** https://forum.kirupa.com/t/you-can-help-me-in-hittest-so-please-enter/192249
**Category:** Uncategorized
**Created:** [June 27, 2006, 8:23am UTC](https://forum.kirupa.com/t/you-can-help-me-in-hittest-so-please-enter/192249 "2006-06-27T08:23:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![engghost](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@engghost](https://forum.kirupa.com/u/engghost)
#### Post date: [June 27, 2006, 8:23am UTC](https://forum.kirupa.com/t/you-can-help-me-in-hittest-so-please-enter/192249/1 "2006-06-27T08:23:50Z")

</div>

as usual , u got start with a broad smile :pleased:  
then try to ask .

here is my problem , i’m designing some game that need to deal with collosion ,  
when the ball hit the walls it must change the directions of both \_x and \_y and no problem till now ,  
the problam appear after we put an obstruction -square- in our stage ,  
if we still order flash to change both directions of the ball if it hit the obstruction ,  
a fatal error 'll hapen , so one direction only got to be changed , and this is only works if the ball hit the obstruction in only two parallel sides, if the ball hits the other two parallel sides the error came again , :snooze: :snooze: :snooze:  
i know that u r about to sleep

but let forget all these words , :ub: , and just watch the attatched file ,  
and the code is here :  
all in the movie clip instance “ball” , the square instance “land”

```auto
onClipEvent (load) {
 speedX = 20;
 speedY = 20;
}
onClipEvent (enterFrame) {
 this._x += speedX;
 this._y += speedY;
 if (this.hitTest(_root.land)) {
  speedX = -speedX;
  speedY = speedY;
 }
 if (this._x>=550) {
  speedX = -speedX;
 } else if (this._x<=0) {
  speedX = -speedX;
 }
 if (this._y>=400) {
  speedY = -speedY;
 } else if (this._y<=0) {
  speedY = -speedY;
 }
}

```

u 'll got the point  
hope you can help :+)
