Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 4 of 4

Thread: Collision Tests with Walls, Obstacles, etc.

  1. #1
    113
    posts
    Game-Designer in Training

    Fla Script Collision Tests with Walls, Obstacles, etc.

    Very simple question (I'm an AS n00b, I know...):

    What's the best way to stop a Movie Clip's movement in a specific direction (ie. when you move into a wall or the side of the stage)?


    Thanks!


    EDIT: this is Flash MX I'm using.
    Last edited by JapanMan; June 21st, 2008 at 07:13 PM.

  2. #2
    i usually test a point in the direction they are trying to move with hitTest(x + x_speed, y + y_speed) first, and then only move if it's clear. some people i think move, then test, then move back if something is hit.

    something like this:

    Code:
    if (Key.isDown(Key.RIGHT)) {
      x_speed = 5;
      y_speed =0;
    }
    
    // more of these for directions
    
    if (_root.clipping_map.hitTest(_x + x_speed, _y + y_speed) == false) {
      _x += x_speed;
      _y += y_speed;
    }

  3. #3
    113
    posts
    Game-Designer in Training
    so, in the instance of your code, "map" would be the wall or obstacle, and the code would be in the moving Movie Clip's actions, correct?

  4. #4
    yeah, clipping_map is just a vector drawing with solid where they can't walk, and you can do onClipEvent(load) { _visible = false; } in it to make it invisible. and the code in the example is attached to the moving movie clip.

    uh, i messed up a line tho. it should say:

    if (_root.clipping_map.hitTest(_x + x_speed, _y + y_speed, true) == false) {

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012