A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Collision Detection

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    4

    Collision Detection

    Hey there.

    I'm trying to make a simple maze game where I control the object that needs to be moved inside the maze. The movement part is simple enough, however, I want to make a collision detection thingy that will make the player lose if he runs into one of the walls in the maze.
    I've looked up a bunch of collision detection videos and tutorials, but for the most part it only explains how to make flash *state* that there's a collision, such as in here:
    http://www.actionscript.org/resource...ion/Page1.html
    rather then letting me actually do something.

    Basiclly, something like this:
    http://www.ekme.net/play/keyboard-maze.html
    When the player hits one of the yellow things, the game resets.

    I'd appreciate any help, and thanks in advance.

  2. #2
    Senior Member
    Join Date
    Jan 2010
    Location
    England
    Posts
    268
    id do it with hitTests.
    try something like
    Code:
    objecttohit.onEnterFrame = function() {
    	if (controllableMC.hitTest(objecttohit)) {
    gotoAndPlay(2)
    }
    }
    for this when you hit the maze edge you will go to the second frame where you would write "you lose" or something...OR instead of having a simple gotoAndPlay job you could reset the position of the controlable movie clip to the start, depending where you put the character just add

    Code:
    controllableMC._x = 100
    controllableMC._y = 100
    controllableMC is the instance name of the character you are moving
    objecttohit is the instance name of the maze you are hitting.
    Last edited by stevehungry; 03-21-2010 at 06:56 PM.
    might be addicted to flash...
    _______________________________________

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    4
    Thank you for the reply, but I suppose I just didnt explain myself properly.
    I need the code for Actionscript 3.0
    the Code you presented appears to work with 2.0 indeed, but I need 3.0 support.
    Any ideas?
    Again, thanks in advance.

  4. #4
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Try incorporating the hitTestObject method,
    Actionscript Code:
    if(mc.hitTestObject(other_mc)) {
        // actions
    }
    Wile E. Coyote - "Clear as mud?"

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