# Hitting a wall

**URL:** <https://forum.kirupa.com/t/hitting-a-wall/60472>\
**Category:** programming\
**Created:** [August 10, 2004, 4:58am UTC](https://forum.kirupa.com/t/hitting-a-wall/60472 "2004-08-10T04:58:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gravy](https://avatars.discourse-cdn.com/v4/letter/g/a587f6/32.png) [@gravy](https://forum.kirupa.com/u/gravy)\
**Post date:** [August 10, 2004, 4:58am UTC](https://forum.kirupa.com/t/hitting-a-wall/60472/1 "2004-08-10T04:58:17Z")

</div>

Thats basically my question. How do you get it so that when a movieclip hits a boundry it cant move in that direction? I came up with this:

```auto

onClipEvent (enterFrame) {
if (hitTest(_root.wall)) {
_root.guy.movespeed = 0;
}
} 

```

But it stopped the movieclip before it even touched the wall, and you could move a short distance if you let go of right/left until you eventually passed the boundry anyway. Any Suggestions?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2004, 7:31am UTC](https://forum.kirupa.com/t/hitting-a-wall/60472/2 "2004-08-10T07:31:45Z")

</div>

im no great Expert yet…infact i just started my self. this forum is a great place to learn. i just learned clipping the other day…use something like this

if(this.hitTest(\_root.wall)) {  
\_y -= speed;  
}

for down use this \_y -= speed;  
for up \_y += speed;  
for right \_x -= speed;  
for left \_x += speed;

im not to good at explaining things but if you are confused with this i can try fixing your source manually… @.@

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 10, 2004, 12:25pm UTC](https://forum.kirupa.com/t/hitting-a-wall/60472/3 "2004-08-10T12:25:09Z")

</div>

What I did in my RPG when the character hits the wall, rather than changing the character speed, I moved it negatively.  
Something like:

```auto

if(keyPress(key.RIGHT){
character._x += character_speed;
}

```

And then on the objects that would have hit detection, simply do a movement in the opposite direction:

```auto

if(_root.character.hitTest(this)){
character._x -= character_speed;
}
 
So far, it is working flawlessly for me. I don't ever have to worry about changing the character speed to one thing or another, and since both of the codes can be executed on keyPress, the will work at the same time, thereby nullifying your characters movement.
 
I think that is what Bahamut was getting at.
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 2:37am UTC](https://forum.kirupa.com/t/hitting-a-wall/60472/4 "2004-08-11T02:37:40Z")

</div>

thats exactily what i was saying…see i can never be a teacher lol…@.@ oroo
