A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: CS4: hitTestObject allows MC to pass through..???

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    9

    Angry CS4: hitTestObject allows MC to pass through..???

    I am trying to develop a basic game engine for a slime soccer style game where a player can move around and jump. I am still fairly new at AS3 but managed to put together this working bit of code that the game currently runs on:
    Code:
    stop();
    	//vardefs
    	var runSpeed:Number = 10;
    	var blueGoals:Number = 0;
    	var redGoals:Number = 0;
    	var blueGotGoal:Boolean = false;
    	var redGotGoal:Boolean = false;
    			var blueLeftTrue:Boolean = false;
    			var blueRightTrue:Boolean = false;
    			var redLeftTrue:Boolean = false;
    			var redRightTrue:Boolean = false;
    			var blueOnGround:Boolean = false;
    			var redOnGround:Boolean = false;
    				//gravfunctions::
    		var gravPull:Number = 0.5;
    		var yPullSpeed:Number = 0;
    				//jumpfunctions::
    		var jumpSpeed:Number = 2.103;
    	//trace(String(blueLeftTrue));
    function checkSideMotion(Event:KeyboardEvent){
    	if(Event.keyCode == 37){
    		blueLeftTrue = true;
    	}
    	if(Event.keyCode == 39){
    		blueRightTrue = true;
    	}
    }
    function sideMotionFalse(event:KeyboardEvent){
    	if(event.keyCode == 37){
    		event.keyCode = 0;
    		blueLeftTrue = false;
    		trace("false");
    	}
    	if(event.keyCode == 39){
    		event.keyCode = 0;
    		blueRightTrue = false;
    		trace("false");
    	}
    }
    	//trace(String(blueLeftTrue));
    function sideMovement(Event){
    	if(blueLeftTrue == true){
    		mc_Slime1.x-= runSpeed;
    		trace("Blue Left Is True")
    	}
    	if(blueRightTrue == true){
    		mc_Slime1.x+= runSpeed;
    		trace("Blue Right Is True")
    	}
    }
    function blueGravity(event:Event){
    	if(mc_Slime1.hitTestObject(mc_Grass)){
    		blueOnGround = true;
    		mc_Slime1.y = mc_Slime1.y;
    		trace("blueOnGround = true;");
    	}else{
    		if(blueOnGround == false){
    			yPullSpeed += gravPull;
    			mc_Slime1.y += yPullSpeed;
    			blueOnGround = false;
    			trace("blueOnGround = false;")
    		}
    	}
    }
    	//trace(String(blueLeftTrue));
    stage.addEventListener(KeyboardEvent.KEY_DOWN, checkSideMotion);
    stage.addEventListener(Event.ENTER_FRAME, sideMovement);
    stage.addEventListener(KeyboardEvent.KEY_UP, sideMotionFalse);
    stage.addEventListener(Event.ENTER_FRAME, blueGravity);
    The problem is, the "slime" mc actually falls a little bit through the grass layer. what can I do to fix this??

    ALSO. Can anybody point me in the right direction as far as a script that makes the MC "jump", still being affected by gravity?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to remove the event listener when hitting has occurred.
    stage.removeEventListener(Event.ENTER_FRAME, blueGravity);

    Also it is better to use the Timer class, since ENTER_FRAME is dependent on the framerate.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    I added that line of code into the blueGravity function but I still have the same problem.

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    Also, what can I do to add the ability of the mc_Slime1 to jump?

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    One question for one thread. Did you try the timer with 1ms delay? Enterframe is really not good to use. Also I don't know how the movieclip shapes look like.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center