0
votes

I can stop PacMan going through the wall one way but he can go through the wall when going in the other direction, the code i have used is:

onClipEvent (enterFrame) {
if (_root.char.hitTest(this))
{
    _root.char._x -= 7;
}

}

I need him to not go through the wall when travelling in either direction! thanks in advance

1

1 Answers

0
votes

You are facing a bug like this, because, when you modifying heroe's "x" property, you always decrease it. So, in one direction, when you move from left to right and increasing object's "x" value, you code works fine. But when you're moving in opposite direction, you decrease "x" value and on collison your object will be just a little speeded up (by 7 pixels).

To avoid this bug you have to decrease your object's "x" only when it is increasing during moving, in other situations, you must increase it.