Collision for 2D scroller.

I need help creating collision for this simple 2D scroller in ActionScript. I want the collision to detect when the player hits a wall and makes the player stop moving. The sample below is similiar to how I have the program to detect if the player is actually on the ground and it registers that just fine. But when I try to change it around to stop the player from moving pass the wall it does not work. Can someone please help me.


This is the code for my project:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//checking for hitting a wall
	for(var i:int = 0;i<blockHolder.numChildren; i++){
		//getting the current block
		var hitBlock:DisplayObject = blockHolder.getChildAt(i);
		//checking hit test and if main is passed the brick
		if(mcMain.hitTestObject(hitBlock) && hitBlock.x < mcMain.x ){
			
			mainHitWall = true;	
			
			mainSpeed = mainSpeedWall;
			
			
			break;
			}
		mainHitWall = false;
	}
Topic archived. No new replies allowed.