Be a Supporter!

percentage hittest?

  • 347 Views
  • 5 Replies
New Topic Respond to this Topic
Lesbian-Waffles
Lesbian-Waffles
  • Member since: Dec. 8, 2006
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
percentage hittest? 2009-03-12 00:36:05 Reply

I'm making a game in which a character can hide behind walls. I need to design a way for the enemies to know how much is exposed and what parts. I've come up with a few theories but the easiest is if there was a simple way i could check to overlapping shape flags and get a value of how much is overlapping with a few formulas. is there ANY way this can be done? I'm using ASC2, but ill take ASC3 advice and see what i can adapt.

Simple concept:

if less than 50% of head_mc is behind wall_mc, visual = true.

I could do multiple points, but there are a few flaws i would design around that would be unwanted. Example...what if a tree is covering the points but 60% of the body part is visible. my enemy needs to confirm that 60% is available to shoot and to start shooting there.

Ransom09
Ransom09
  • Member since: Aug. 5, 2003
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to percentage hittest? 2009-03-12 01:21:20 Reply

I would maybe try first asking if the part is touching a wall. If not, it's exposed, if yes, then ask about it's _x and _y values in comparison to the wall it's touching to see how close/far it is.

henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to percentage hittest? 2009-03-12 02:02:14 Reply

This sounds like a good time to not use hittest and learn how to do it with simple math.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to percentage hittest? 2009-03-12 05:54:22 Reply

At 3/12/09 02:02 AM, henke37 wrote: This sounds like a good time to not use hittest and learn how to do it with simple math.

How exactly does this post help the topic starter? If you're going to advocate using maths over hitTests, at least give some basic pointers/code samples on how he could achieve what he wants to do. Saying 'use simple math' is about as useful as saying 'have a waffle for breakfast'.


- - Flash - Music - Images - -

BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to percentage hittest? 2009-03-12 07:57:15 Reply

Right, if you insist, he can probably use basic rectangular hitboxes. Using the rectangle class, you can then subtract the boxes from each other and can easily compute the area of the intersection rectangle divided with the player rectangle, resulting in the ratio of coverage. Or the percent expressed without the percent sign.


Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.

zuperxtreme
zuperxtreme
  • Member since: Jan. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to percentage hittest? 2009-03-12 09:06:40 Reply

You can try out gSkinners collision class: http://www.gskinner.com/blog/archives/20 05/08/flash_8_shape_b.html

It outputs the overlapping surface.


BBS Signature