?
Solved

Actionscript Collision Detection

Posted on 2007-03-30
2
Medium Priority
?
1,611 Views
Last Modified: 2012-05-05
Hi,

I am creating my own version of Pacman as practice for developing flash games. (It is the first one I've ever tried to make).

I have managed to detect a collision with walls etc using mc1.hitTest(mc2)
If the pacman collides with a wall it stops...
The problem I have is if the pacman is between 2 walls (above and below it or to the left and right of it) I want it to only react to the arrow keys in whic directions it can travel.

I.E. if there is a wall above and below it, I want it to only react to the left and right arrow keys...

Using mc1.hitTest(mc2) the pacman reacts to the keypress and just stops where it is, facing the wall either above or below it...

Is there a way to detect if the pacman will collide with a wall before it reacts to the keypress? (hence disabling the keys which point in a direction which the pacman cannot go)

I tried to explain this as best I can. If you need any more information please ask.

Thanks in advance
mms_master
0
Comment
Question by:mms_master
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 18845494
hi, i remember creating one a couple of years ago (Cant' find the file) - but if you think about it, you can't do a hit test until it hits the thing, so maybe a way to hack it, would be to put a bigger invisible bounding box around your item, that way the hit test will kick in earlier.

my 2c worth,
blu.
0
 
LVL 5

Author Comment

by:mms_master
ID: 18876039
Hi,

I actualy found a way to work around it before reading your post, but thanks for your reply.
I hittest the walls to see if any of them hit the point just above/below etc the pacman.
Here is my code so you can understand me better:

if (Key.isDown(Key.RIGHT)) {
                     PathClear = "YES";
      for (i=1; i<=_root.WallCount; i++) {
            if (_root["Wall"+i].hitTest((_root["PacMan"]._x+(_root["PacMan"]._width/2)+2), _root["PacMan"]._y-(_root["PacMan"]._height/2), false)) {
                  PathClear = "NO";
                  break;
            }
            if (_root["Wall"+i].hitTest((_root["PacMan"]._x+(_root["PacMan"]._width/2)+2), _root["PacMan"]._y, false)) {
                  PathClear = "NO";
                  break;
            }
            if (_root["Wall"+i].hitTest((_root["PacMan"]._x+(_root["PacMan"]._width/2)+2), _root["PacMan"]._y+(_root["PacMan"]._height/2), false)) {
                  PathClear = "NO";
                  break;
            }
      }
      if (PathClear == "YES") {
            PlayerDirection = "RIGHT";
      }
}

I will still accept your answer as your solution would have also worked.

Thanks for the help.
mms_master
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question