# Problem with collision

**URL:** <https://forum.kirupa.com/t/problem-with-collision/62350>\
**Category:** programming\
**Created:** [August 27, 2004, 2:19am UTC](https://forum.kirupa.com/t/problem-with-collision/62350 "2004-08-27T02:19:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![acor](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@acor](https://forum.kirupa.com/u/acor)\
**Post date:** [August 27, 2004, 2:19am UTC](https://forum.kirupa.com/t/problem-with-collision/62350/1 "2004-08-27T02:19:43Z")

</div>

I seem to be having a problem with the “hittest” function. My character will go straight through any object I put infront of it.

Heres the code for “characterf”:

_onClipEvent (load) {_  
_moveSpeed = 5;_  
_}_  
_onClipEvent (enterFrame) {_  
_if (Key.isDown (Key.RIGHT)) {_  
_this.\_x += moveSpeed; \_rotation = 0_  
_} else if (Key.isDown (Key.UP)) {_  
\*this.\_y -= moveSpeed; \_rotation = 270 \*  
_} else if (Key.isDown (Key.DOWN)) {_  
_this.\_y += moveSpeed; \_rotation = 90_  
_} else if (Key.isDown (Key.LEFT)) {_  
_this.\_x -= moveSpeed; \_rotation = 180_  
_}_  
_}_

Heres the code for “wall1”:

_onClipEvent (load) {_  
_if(\_root.characterf.hitTest(this)){_  
_characterf.\_x -= 5;_  
_}_  
_}_

I would post the fla but i dont know how. And does anyone know how to invert a movie clip along the X axis on a key hit? I would prefer “characterf” to:

_else if (Key.isDown (Key.LEFT)) {_  
_this.\_x -= moveSpeed; \_rotation =_ **X\_INVERT**  
\*} \*or something…

---

<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 27, 2004, 3:11am UTC](https://forum.kirupa.com/t/problem-with-collision/62350/2 "2004-08-27T03:11:52Z")

</div>

onClipEvent(enterFrame)//NEED THE ENTER FRAME  
if (this.hitTest(\_root.characterf)){  
\_root.characterf.\_x-=5;  
}  
}

and about the inverting…maybe you could try this.\_xscale

---

<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 27, 2004, 3:36am UTC](https://forum.kirupa.com/t/problem-with-collision/62350/3 "2004-08-27T03:36:19Z")

</div>

> [@Moopers](#):
>
> onClipEvent(enterFrame)//NEED THE ENTER FRAME  
> if (this.hitTest(\_root.characterf)){  
> \_root.characterf.\_x-=5;  
> }  
> }
> 
> and about the inverting…maybe you could try this.\_xscale

nevermind i got it to work but the movie clip now goes straight through the wall and then cant go back through it. Heres the revised code for “wall1”

_onClipEvent (enterFrame) {_  
_if (this.hitTest(\_root.characterf)) {_  
_\_root.characterf.\_x = 1;_  
_}_  
_}_

_ive been playing with the x values but nothing seems to be working_

---

<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 27, 2004, 4:41am UTC](https://forum.kirupa.com/t/problem-with-collision/62350/4 "2004-08-27T04:41:44Z")

</div>

nevermind I got it working. Although I would still like an answer to the invert movie clip question

---

<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 27, 2004, 1:22pm UTC](https://forum.kirupa.com/t/problem-with-collision/62350/5 "2004-08-27T13:22:17Z")

</div>

like i said, you could use the \_xscale way. if you have an object and you want to invert it 100%, do something like this  
onClipEvent(enterFrame){  
this.\_xscale=-100;  
}

if you want it to continue inverting itself maybe something like this  
onClipEvent (enterFrame){  
this.\_xscale+=3;  
}
