8 Replies Latest reply on Jan 21, 2008 4:09 PM by Newsgroup_User

# 2d collision

I'm creating a game where various object have to be inserted into odd shaped
objects. What's the best way to detect if a particular point is on one side
or another of a shape or curve?

• ###### 1. Re: 2d collision
Have you tried sprite...intersects ?

"compares the position of two sprites to determine whether the quad of sprite1 touches (TRUE) or does not touch (FALSE) the quad of sprite2."
"If both sprites have matte ink, their actual outlines, not the quads, are used. "

See Director Documentation, search for "Intersecting Sprites"
• ###### 2. Re: 2d collision
you can use sprite(x).within(sprite(y))... however, there are two caveats:
1) you need to use matte ink in order to ignore the object's bounding rectangle so it will test the shape only.
2) using matte ink to get the proper behaviour seems to only work on shape members and not 32-bit alpha images or vectorshape images. I have not tested with flash members.
• ###### 3. Re: 2d collision
I knew about those things but what I didn't mention was that the sprites
have alpha channels their edges are quite feathered so the traditional
techniques aren't accurate.

I suppose syncing a more descretely edged sprite with the ones I mention
above will offer the edge I'm looking for.

"womp" <lingoforum@wordofmo.com> wrote in message
news:fmjbg7\$i2v\$1@forums.macromedia.com...
> I'm creating a game where various object have to be inserted into odd
> shaped objects. What's the best way to detect if a particular point is on
> one side or another of a shape or curve?
>
>
>

• ###### 4. Re: 2d collision
"womp" <lingoforum@wordofmo.com> posted in macromedia.director.lingo:

> I knew about those things but what I didn't mention was that the sprites
> have alpha channels their edges are quite feathered so the traditional
> techniques aren't accurate.

Does changing the cast member's Alpha Threshold help?

--
Mark A. Boyd
Keep-On-Learnin' :)
• ###### 5. Re: 2d collision
I'll have to try that. I generally haven't messed with that. I suppose
that changes the feathering tolerance of graphics right?

To further explain, I'm working on a medical project where user's will use
the mouse to insert an IUD into a graphic -you know what-

I need to be able to detect when the insertion device's tip is against any
of the boundries...imagine using the mouse to insert a thermometer into a
mouth and having to detect anytime the thermometer hits the lips, inside
wall of the mouth, etc. Of course, the tip might not be touching anything
but if the side of the thermometer were to touch the lips after the tip has
passed them, that would have to be detected also.

In my project, it's pretty much 2d, just as if in the mouth example, the
graphic was a cross section of the head from the side and one only needed to
worry about any surfaces in the plane of the screen.

Babbling never helps. Anyway, I think that using the matte ink with the
"intersect" or "within" Lingo will work. If the alpha gets in the way of
accuracy I could always create a 2 bit graphic of the exact boundries and
have that move in sync with the device but set the blend of the border
graphic to zero. This will give me more definitive boundries.

Craig

"Mark A. Boyd" <lingoboyd@mboydDotcom.invalid> wrote in message
news:Xns9A27B2C529CC9mblistssanDotrrcom@216.104.212.96...
> "womp" <lingoforum@wordofmo.com> posted in macromedia.director.lingo:
>
>> I knew about those things but what I didn't mention was that the sprites
>> have alpha channels their edges are quite feathered so the traditional
>> techniques aren't accurate.
>
> Does changing the cast member's Alpha Threshold help?
>
>
> --
> Mark A. Boyd
> Keep-On-Learnin' :)

• ###### 6. Re: 2d collision
"womp" <lingoforum@wordofmo.com> posted in macromedia.director.lingo:

> I'll have to try that. I generally haven't messed with that. I suppose
> that changes the feathering tolerance of graphics right?

That's the basics of it. It's choosing from 256 levels of the transparency.

I used it on images with soft drop-shadows that were getting in the way of
allowing a user to click & drag sprites around. So I know it works for mouse
clicks. I don't recall trying it with intersects or within.

--
Mark A. Boyd
Keep-On-Learnin' :)
• ###### 7. Re: 2d collision
Hi Craig,

You might want to consider a combination of approaches - such using the intersection of the bounding box around the device and the obstacles to generate a list of potential collisions. Then, check the specific collisions. If you want the point of collisions (rather than simply knowing that there was a collision), you might consider using line segments (ie define the obstacles as a series of lines, curves or quads and using some funky maths to check if they intersect -- see for example http://www.lingoworkshop.com/Testzone/Intersecting_Circles.php and http://www.lingoworkshop.com/code/classes/scripts/MathsLib.Geom.ls )

-- Luke
• ###### 8. Re: 2d collision
Good stuff Luke. Thanks.

"Lukewig" <webforumsuser@macromedia.com> wrote in message
news:fn0ilc\$eu0\$1@forums.macromedia.com...
> Hi Craig,
>
> You might want to consider a combination of approaches - such using the
> intersection of the bounding box around the device and the obstacles to
> generate a list of potential collisions. Then, check the specific
> collisions. If you want the point of collisions (rather than simply
> knowing
> that there was a collision), you might consider using line segments (ie
> define
> the obstacles as a series of lines, curves or quads and using some funky
> maths
> to check if they intersect -- see for example
> http://www.lingoworkshop.com/Testzone/Intersecting_Circles.php and
> http://www.lingoworkshop.com/code/classes/scripts/MathsLib.Geom.ls )
>
> -- Luke
>