Forum Topic: hitTests -- WTF

(301 views • 12 replies)

This topic is 1 page long.

<< < > >>
Mad as Hell

Archon68

Reply To Post Reply & Quote

Posted at: 7/18/09 10:47 AM

Archon68 LIGHT LEVEL 22

Sign-Up: 09/09/07

Posts: 3,431

How come this code "works":

onEnterFrame = function(){
  if(player.hitTest(_root.ground)){
    trace("hitting");
  }
}

and these don't:

onEnterFrame = function(){
  if(player.hitTest(_root.ground._x, _root.ground._y, true)){
    trace("hitting");
  }
}
onEnterFrame = function(){
  if(player.hitTest(_root.ground._x, _root.ground._y, false)){
    trace("hitting");
  }
}

WTF? I'd use the first one, but that registers hitTests with the bounding box, not the actual shape.

What's wrong?

I code in AS2, in case I forgot to mention it.

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 7/18/09 10:53 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,528

You have to do it the other way around. The ground's x and y (it's registration point) are at one small point on the ground movieclip (Look for the little 'cross')... so it will only check if the player is hitting that tiny point, and not anywhere on the ground.

What you want to do is put the player's registration point at his feet, and then check the ground AGAINST that.

if(ground.hitTest(player._x, player._y, true))

All sites currently down. Deal with it. <3

BBS Signature

None

51lver

Reply To Post Reply & Quote

Posted at: 7/18/09 10:53 AM

51lver EVIL LEVEL 21

Sign-Up: 01/14/08

Posts: 513

because you're checking the ground's _x, _y not the players, so the player will have to hit the one spot on the ground for the hittest to work

onEnterFrame = function(){
if(player.hitTest(_root.ground._x, _root.ground._y, true)){
trace("hitting");
}
}

try:

onEnterFrame = function(){
if(_root.ground.hitTest(player_x, player._y, true)){
trace("HITTING");
}
}

None

Archon68

Reply To Post Reply & Quote

Posted at: 7/18/09 10:59 AM

Archon68 LIGHT LEVEL 22

Sign-Up: 09/09/07

Posts: 3,431

Thanks guys... hitTests are messed up IMO.

I code in AS2, in case I forgot to mention it.

BBS Signature

None

CHINESEMANZOMG

Reply To Post Reply & Quote

Posted at: 7/18/09 11:03 AM

CHINESEMANZOMG NEUTRAL LEVEL 02

Sign-Up: 04/01/09

Posts: 79

At 7/18/09 10:59 AM, Archon68 wrote: Thanks guys... hitTests are messed up IMO.

No, you just don't know how to use them.


None

Johnny

Reply To Post Reply & Quote

Posted at: 7/18/09 11:08 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,528

At 7/18/09 11:03 AM, CHINESEMANZOMG wrote:
At 7/18/09 10:59 AM, Archon68 wrote: Thanks guys... hitTests are messed up IMO.
No, you just don't know how to use them.

No, I know how to use them... and I agree with him. It's backwards.

It is more intuitive to check if the player is hitting the ground, not if the ground is hitting the player, so for someone new to programming, that's what they're going to check. If the player is hitting the ground.

In real life, you'd say "Am I standing on the ground?" not "Is the ground keeping me from falling through it"

Blah.. blah.. newton's law, equal/opposite reaction, they're hitting each other I know... but from a basic view, it's more natural to check if the player is hitting the ground.

All sites currently down. Deal with it. <3

BBS Signature

None

Archon68

Reply To Post Reply & Quote

Posted at: 7/18/09 11:35 AM

Archon68 LIGHT LEVEL 22

Sign-Up: 09/09/07

Posts: 3,431

At 7/18/09 11:08 AM, Johnny wrote: It is more intuitive to check if the player is hitting the ground, not if the ground is hitting the player, so for someone new to programming, that's what they're going to check. If the player is hitting the ground.

I'm not new to programming, just annoyed with hitTests, I can never remember which way to use them.

Other than that, I agree with you completely.

I code in AS2, in case I forgot to mention it.

BBS Signature

None

Johnny

Reply To Post Reply & Quote

Posted at: 7/18/09 11:43 AM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,528

At 7/18/09 11:35 AM, Archon68 wrote: I'm not new to programming, just annoyed with hitTests, I can never remember which way to use them.

Please don't argue that.

If you had trouble remembering how to properly use a hitTest, to the point where you had to ask for advice on one of the most basic methods and to not be able to easily figure out that the position of a registration point was the culprit, you're still new enough to actionscript to warrant being called so. It's not an attack at you. It's a reality is all.

If you argue against it, then instead of being 'new'... you're just a little 'slow.'

So you can take 'slow' or 'new'

Your choice.

All sites currently down. Deal with it. <3

BBS Signature

None

Archon68

Reply To Post Reply & Quote

Posted at: 7/18/09 11:50 AM

Archon68 LIGHT LEVEL 22

Sign-Up: 09/09/07

Posts: 3,431

Fine, I'm relatively new to hitTests, just not AS in General.

I code in AS2, in case I forgot to mention it.

BBS Signature

Expressionless

zedd56

Reply To Post Reply & Quote

Posted at: 7/18/09 12:16 PM

zedd56 LIGHT LEVEL 14

Sign-Up: 08/31/07

Posts: 1,475

the entire issue is that you cannot check for contact between the true shapeflags of both objects. You can test a true shapeflag against a bounding box or a true shapeflag against a point. Not a true shapeflag against another true shapeflag, which we game designers need oh so badly.

Very stupid imo, could probably be done by adobe but meh, what are you gonna do?


None

UnknownFury

Reply To Post Reply & Quote

Posted at: 7/18/09 12:25 PM

UnknownFury EVIL LEVEL 26

Sign-Up: 08/10/05

Posts: 6,027

At 7/18/09 12:16 PM, zedd56 wrote: Very stupid imo, could probably be done by adobe but meh, what are you gonna do?

Implement it yourself. There isn't a mega quick way of just testing any two shapes, it depends on your set up.

Portfolio(Under construction): UnknownFury.com |
Msn: giant_ak_47@msn.com | Contact: me@unknownfury.com
Follow me on twitter!


None

Coolio-Niato

Reply To Post Reply & Quote

Posted at: 7/18/09 12:30 PM

Coolio-Niato LIGHT LEVEL 28

Sign-Up: 06/30/05

Posts: 1,774

Once you start going into vector collision detections, all your hitTest troubles will be gone. Otherwise, just learn how to properly use hitTest and it'll work great 95% of the time.

=)

BBS Signature

None

4urentertainment

Reply To Post Reply & Quote

Posted at: 7/18/09 02:44 PM

4urentertainment NEUTRAL LEVEL 13

Sign-Up: 08/01/08

Posts: 1,599

At 7/18/09 12:30 PM, Coolio-Niato wrote: Once you start going into vector collision detections, all your hitTest troubles will be gone. Otherwise, just learn how to properly use hitTest and it'll work great 95% of the time.

I know bitmap collision detection, but I never heard of vector collision detection..

"When you look at yourself from a universal standpoint, something inside always reminds or informs you that there are bigger and better things to worry about. "- Einstein


All times are Eastern Standard Time (GMT -5) | Current Time: 01:03 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!