Help with hitTest()

  • Dally315
  • Born
  • Born
  • Dally315
  • Posts: 3

Post 3+ Months Ago

Ok, here's my basic problem. I have two MCs and I want to test for collision, so I am using the hitTest function. When the two MCs collide I want them to play frame 2 of their respective MCs. This is working to an extent. The problem is that as long as they stay in contact with each other nothing happens. When they separate I get the desired effect. Does anyone know how why this is happening? I would like them to play frame 2 as soon as they come in contact. Any help would be greatly appreciated. Thanks in advance.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • elibol
  • Novice
  • Novice
  • elibol
  • Posts: 29

Post 3+ Months Ago

when they collide do they overlap? i've never used the hitTest function so i dont know what kind of collision detection it is... whatever function is invoked when they both intersect you need to check for consistency. pop some trace actions to make sure your code is taking the route you want it to be.

my guess on the problem is that they are overlapping, thus constantly executing the function that is suppose to gotoAndPlay(2), so it is on frame 2 until this function is no longer invoked... hence when they are nolonger touching each other.

a solution to this problem would be to only invoke the function when the mc is on frame 1. so within your invoked function encapsulating your could there could be something like:
Code: [ Select ]
if(this._currentframe == 1){
//your code
}
  1. if(this._currentframe == 1){
  2. //your code
  3. }
  • Dally315
  • Born
  • Born
  • Dally315
  • Posts: 3

Post 3+ Months Ago

Once I tested for currentframe == 1 it worked perfectly. Thanks so much.
  • bryanatncsu
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5

Post 3+ Months Ago

At Macromedia.com they have ample information about its functionality. I have a specific question regarding the "shape" in which it detects collisions.

For example, they have a square used at macromedia.com.
That is fairly simple to program by hand using the _x and _y values. But something like Hittest could avoid lots of unnecessary loops in certain cases. If you were making pacman you wouldn't have to compare him to every piece of wall, only the ones that he encounters from hittest().

My question:

Is Hittest "smart" enough to detect all kinds of shapes? If so, what shapes are available besides the square?
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

HitTest alone is not smart enough, it's actually rather retarded when it comes to shape detection so you can really only do a square. You will need to combine hitTest with getBounds for better shape detection.

This file is kind of old, so the code could use a wee bit of improving, but I honestly just don't feel like it....lol. I'm falling into my 'eh, it works' mode.

http://www.lostinbeta.com/ozzu/wallHit.fla



Note: getBounds is a complicated thing to grasp... I had to read up on it for like ages before I even understood what the heck it was.

http://www.macromedia.com/support/flash ... ry523.html

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.