hitTest and Collision problems

I’m having a lot of trouble with this hitTest method. Well… I’ll explain it to you. I made a wall, and if my player collides into that wall I want him to stop and not be able to move. So I can check for a hitTest before I move. If I go :

if(Player.hitTest(wall))
return;

thus causing it to ignore all movment controls, the problem with that is that I can’t move, So I tried another method.

if(player.hitTest(wall)
{
player._x-=ThePlayerSpeed;
}

The problem with that is that if I hold the up button my player will keep bouncing off the wall, and I want him to not even move going up, but still be able to move going down, right, and left.

I’ve never worked with MX2004, but maybe you could have a set of four Boolean variables.

canMoveRight
canMoveLeft
canMoveUp
canMoveDown

To start with, all of those would be ‘true’.

Then whenever you try to move your character, you’d check to see whether movement in
a particular direction was allowed.

When they hit the wall, they lose the ability to move up

if(Player.hitTest(wall))
{
canMoveUp = false;
}

but movement in the other directions is still allowed.

If you have other obstacles that take away their ability to move in a particular direction
you could simply set the appropriate Boolean to false in your other hit test(s).

I was going to do that, but I thought it would have been sloppy coding. However I trust you have far more experiance in this language then I, so I’ll trying using an array of booleans. Thanks.

You could do something like this.

if( !_root.wall.hitTest(_x,_y))
{
this._x+=1;
}
else
{
this._x = _x;
}

Hope this works :angel: