# Walls with hitTests not working (AS 1 & 2)

**URL:** <https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446>\
**Category:** Uncategorized\
**Created:** [June 5, 2008, 11:17pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446 "2008-06-05T23:17:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 5, 2008, 11:17pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/1 "2008-06-05T23:17:17Z")

</div>

I would like to know how to simply use hittests to block players (using the arrow keys to move) and npc characters. I’ve seen tons of tutorials and none of them have worked when I did it.  
 ![](http://forum.kirupa.com/uploads/kirupa/4788/2325208af18f68bc.gif)

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 5, 2008, 11:19pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/2 "2008-06-05T23:19:01Z")

</div>

What specifically did not work with the code you used?

[ot]That is \*weirdest \*way to close a post I’ve seen all week![/ot]

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 5, 2008, 11:22pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/3 "2008-06-05T23:22:36Z")

</div>

the entire code is ignored and the player goes right through the wall

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 5, 2008, 11:25pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/4 "2008-06-05T23:25:16Z")

</div>

Post your code, we’re not mind readers. 🙂

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 5, 2008, 11:41pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/5 "2008-06-05T23:41:28Z")

</div>

sorry,

in the player:

on(load){  
playerspeed = 5

onClipEvent(enterFrame){  
if(key.isDown(key.UP)){  
this.\_y -= playerspeed  
}  
if(key.isDown(key.UP)){  
this.\_y -= playerspeed  
}  
if(key.isDown(key.DOWN)){  
this.\_y += playerspeed  
}  
if(key.isDown(key.LEFT)){  
this.\_y -= playerspeed  
}  
if(key.isDown(key.RIGHT)){  
this.\_y += playerspeed  
}  
if(this.hitest(wall)){  
playerspeed = 0  
}else{  
playerspeed = 5  
}  
}

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [June 6, 2008, 4:26am UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/6 "2008-06-06T04:26:15Z")

</div>

The method is _hitTest_, not hitest.

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 6, 2008, 7:37pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/7 "2008-06-06T19:37:55Z")

</div>

I know, I made a typo  
 ![](http://forum.kirupa.com/uploads/kirupa/4788/2325208af18f68bc.gif)

---

<div class="post-metadata">

**Author:** ![indiasfinest](https://avatars.discourse-cdn.com/v4/letter/i/5e9695/32.png) [@indiasfinest](https://forum.kirupa.com/u/indiasfinest)\
**Post date:** [June 9, 2008, 4:18am UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/8 "2008-06-09T04:18:37Z")

</div>

because you’re doing it on load, doing it on enterFrame

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 10, 2008, 3:34pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/9 "2008-06-10T15:34:29Z")

</div>

thanx

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 10, 2008, 4:48pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/10 "2008-06-10T16:48:05Z")

</div>

so how would i write the code correctly in flash 8?

---

<div class="post-metadata">

**Author:** ![npgames](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/npgames/32/2914_2.png) [@npgames](https://forum.kirupa.com/u/npgames)\
**Post date:** [June 10, 2008, 5:14pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/11 "2008-06-10T17:14:29Z")

</div>

you need to close your on(load){

---

<div class="post-metadata">

**Author:** ![evilexplorer](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilexplorer](https://forum.kirupa.com/u/evilexplorer)\
**Post date:** [June 12, 2008, 1:01am UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/12 "2008-06-12T01:01:51Z")

</div>

I forgot to close it after “playerspeed” ---- typo!!!

still wondering though

---

<div class="post-metadata">

**Author:** ![npgames](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/npgames/32/2914_2.png) [@npgames](https://forum.kirupa.com/u/npgames)\
**Post date:** [June 13, 2008, 8:44pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/13 "2008-06-13T20:44:43Z")

</div>

well if you closed the load and changed hitest to hitTest, then the only thing i can think of is to change this line

if(this.hitest(wall)){

to this lind

if(this.hitTest(\_root.wall)){

you are using instance names right?

---

<div class="post-metadata">

**Author:** ![Giferd](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@Giferd](https://forum.kirupa.com/u/Giferd)\
**Post date:** [June 15, 2008, 1:11pm UTC](https://forum.kirupa.com/t/walls-with-hittests-not-working-as-1-2/262446/14 "2008-06-15T13:11:15Z")

</div>

hitTest=tests if there is a collision between two diffrent movie clip.

It will take the collision of the bounding boxes of each movie clip.

The correct code for your moving character would be…

onClipEvent(load){  
playerspeed = 5  
}

onClipEvent(enterFrame){  
if (Key.isDown(Key.LEFT)){  
\_x-=speed;  
}  
if (Key.isDown(Key.RIGHT)){  
\_x+=speed;  
}

if(Key.isDown(Key.UP)){  
\_y-=speed  
}  
if(Key.isDown(Key.DOWN)){  
\_y+=speed  
}

```
        if(this.hitTest(_root.wall)){
          playerspeed = 0
                      }else{
          playerspeed = 5
            }

```

}

* * *

or along those lines.
