MovieClip hitTest

Hi,

I’ve created a moving MC (responding on Up,Left,…).
But I want I to NOT move if it’s underneath something like a wall.
I’ve named the wall “muur”. Any suggestions to stop the MC moving if it’s right underneath/above/ left to/right to the wall, so you’ll have to go around the wall. I tried some hitTest stuff, but it didn’t work. Though I think it’s related with hitTest.
Anyone?

Luster,

post the .fla

Here it is.

PS= Only the red one is a wall, the other is a block, it’s supposed to move when pushed against.

name the red square as wall and then paste this script on the dude mc:

[AS]onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x +=20;
this.gotoAndStop( “rechts” );
if(this.hitTest(_parent.wall)){
this._x=_root.wall._x-18;
}

}

 if (Key.isDown(Key.LEFT)) {
	 this._x -=20;
	 this.gotoAndStop( "links");
	 if(this.hitTest(_parent.wall)){
		 this._x=_root.wall._x+18;
	 }

}
if (Key.isDown(Key.UP)) {
this._y -=50;
this.gotoAndStop( “boven” );
if(this.hitTest(_parent.wall)){
this._y=_root.wall._y+50;
}

}
if (Key.isDown(Key.DOWN)) {
this._y +=50;
this.gotoAndStop( “onder” );
if(this.hitTest(_parent.wall)){
this._y=_root.wall._y-50;
}

}

}
[/AS]

hope that helps:rambo: :cap:

Thanks, but it doesn’t sem to work perfectly. If I’m standing under it and I press right it goes to the left and stuff.
Please help.

PS = Why do you use the value “18” and not “20”?

Try this:

[AS]onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x +=20;
this.gotoAndStop( “rechts” );
if(this.hitTest(_parent.wall)){
this._x=_root.wall._x-22;//<–this is the distance from the wall when its touched pressing the right arrow key

            }
            
            
            
    }
    
    
    if (Key.isDown(Key.LEFT)) {
            this._x -=20;
            this.gotoAndStop( "links");
            if(this.hitTest(_parent.wall)){
                    this._x=_root.wall._x+22;
            }
            
            
    }
    if (Key.isDown(Key.UP)) {
            this._y -=50;
            this.gotoAndStop( "boven" );
            if(this.hitTest(_parent.wall)){
                    this._y=_root.wall._y+53;
            }
            
    }
    if (Key.isDown(Key.DOWN)) {
            this._y +=50;
            this.gotoAndStop( "onder" );
            if(this.hitTest(_parent.wall)){
                    this._y=_root.wall._y-53;
            }
            
    }

}[/AS]

did it worked?

No, I’m sorry it didn’t work, but I think I know why.
In the original code the pinguin’s position was set. You could move around and get back on EXACTLY the same position where you started. (Because it uses “20” and “50” values). If you change one of that values (like “50” into “53”) it will run badly, because all the blocks have been set on locations like ( X=40; Y=350) or (X=120;Y=200). The position of all objects on the Y axis must be a multiple of 50 and on the X axis a multiple of 20.
But how do you stop the pinguin without changing its position a single pixel?

I think I have a possibility, but to use it I need to know how you set in an if " if (conditon1) but NOT (condition2)"
Anyone?
Please?