Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

a built in function to detect collision of two moving objects of irregular shape?

LEGEND ,
May 03, 2006 May 03, 2006
Is there a built in function in AS to detect collision of two moving
objects of irregular shape?



TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
aa wrote:
> Is there a built in function in AS to detect collision of two moving
> objects of irregular shape?

ha - if only!!

collision detection is an enormously complex subject.. especially in
flash which often struggles to do the calculations required at a decent
framerate.

this site shows some techniques for collision detection in 2-dimensional
axis-aligned regular shapes - this should give you some idea of just how
damn complex this all is!!
http://www.harveycartel.org/metanet/tutorials.html

It is also possible on occasion to 'cheat' slightly by using invisible
movieclips placed all around the bounds of the irregular shape and then
checking these against another object (test to see whether clip is
within the bounds of the other object).
I used this technique to quite good effect in a car parking game I made
for Zurich Insurance a while back, have a look:
http://www.moloko.f2s.com/parking/
This is only testing a slightly irregular (non-axis aligned) object
against mostly regular axis-aligned shapes, but could be made to work
with irregular shapes I guess. Not sure how though - I got enough into
this to work out that collision detection and physics in games is really
NOT my forte!!



--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
Oh, and download the game from that site as it shows a lot of the code
in action.
http://www.harveycartel.org/metanet/downloads.html

You can also decompile to view the code they're using but it's pretty
complex, and is written in functions rather than OOP which I find makes
it a bit hard to understand!

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
Thanks.
Do you think that collision detection between a ball and an irregular shape
is feasible?

"MOLOKO" <moloko@_underwear_witty.com> wrote in message
news:e39tkk$1k1$1@forums.macromedia.com...
> aa wrote:
> > Is there a built in function in AS to detect collision of two moving
> > objects of irregular shape?
>
> ha - if only!!
>
> collision detection is an enormously complex subject.. especially in
> flash which often struggles to do the calculations required at a decent
> framerate.
>
> this site shows some techniques for collision detection in 2-dimensional
> axis-aligned regular shapes - this should give you some idea of just how
> damn complex this all is!!
> http://www.harveycartel.org/metanet/tutorials.html
>
> It is also possible on occasion to 'cheat' slightly by using invisible
> movieclips placed all around the bounds of the irregular shape and then
> checking these against another object (test to see whether clip is
> within the bounds of the other object).
> I used this technique to quite good effect in a car parking game I made
> for Zurich Insurance a while back, have a look:
> http://www.moloko.f2s.com/parking/
> This is only testing a slightly irregular (non-axis aligned) object
> against mostly regular axis-aligned shapes, but could be made to work
> with irregular shapes I guess. Not sure how though - I got enough into
> this to work out that collision detection and physics in games is really
> NOT my forte!!
>
>
>
> --
> MOLOKO
> Macromedia Certified Flash MX 2004 Developer
> Macromedia Certified Flash MX Developer
> ------------------------------------------------
> ::remove _underwear_ to reply::
> 'There ain't no devil - it's just God when he's drunk' Tom Waits
> ------------------------------------------------
> GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
> VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
aa wrote:
> Thanks.
> Do you think that collision detection between a ball and an irregular shape
> is feasible?

oh it's all feasible I'm sure, it's just a case of working out how the
hell to do it! It's tricky finding any decent resources for ActionScript
- most books give you some basic but nothing like enough to actually
create a game and none I have seen touch on advanced collision
detection. Best place to start might be looking for code in Java as
that's the closest other language to ActionScript so should be quite
readable. If you understand C then there's lots of resources about doing
all this in C, but I didn't understand any of them!

good luck with it.

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 03, 2006 May 03, 2006
>>by using invisible movieclips placed all around the bounds of the irregular shape
If that would be sufficient for your project, there is a tutorial on kirupa.com:
http://www.kirupa.com/developer/actionscript/advanced_collision.htm
Otherwise you could treat the irregular shape as a set of lines (if applicable) and use circle-to-line collision detection to predict a collision.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
LuigiL wrote:
>>> by using invisible movieclips placed all around the bounds of the irregular
> shape
> If that would be sufficient for your project, there is a tutorial on
> kirupa.com:
> http://www.kirupa.com/developer/actionscript/advanced_collision.htm
> Otherwise you could treat the irregular shape as a set of lines (if
> applicable) and use circle-to-line collision detection to predict a collision.
>
yes, that's basically what I used in my parking game initially, however,
hitTest is *incredibly* slow to run. You don't normally notice how slow
until you try using it in a game running at 24fps where the main object
needs to be checked to see whether it's colliding against several other
different objects on screen. So you might have (as in the kirupa
example) 50 movieclips that need to be hit-tested against 5 other
objects 24 times per second. this will be slooooow!

one thing you can do to get around this is check to see if each object
is close enough to bother hittesting on. normally to check distance
between objects in a coordinate space such as Flash's, you would use
pythagoras' theorem - but this involves using square root which is also
dead slow! so, you set up what the minimum distance away something needs
to be before you will bother to try and collision-detect it, then square
that value and call it 'delta'. You can then use the following code to
check if it's within the minimum distance without using square root:
var result = ((this.x1-this.x2)*(this.x1-this.x2)) +
((this.y1-this.y2)*(this.y1-this.y2));//where x1 and y1 are the
coordinates of the main object and x2 and y2 are the coords of the
object you want to test against.
if(result < this.delta) //then object is within range and should be
collision-tested.

unfortunately you'll still find hitTest() quite slow even with some of
the load taken off it - but the only other technique I know that avoids
use of hitTest() only works for testing irregular objects against
axis-aligned rectangular objects so not much use to you :-(

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 03, 2006 May 03, 2006
That's why I said - if it's sufficient for your project. There's no indication of the kind of irregular shape, the collision reaction and if it involves one or more objects.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
LuigiL wrote:
> That's why I said - if it's sufficient for your project. There's no indication of the kind of irregular shape, the collision reaction and if it involves one or more objects.
sorry I wasn't having a go at your post, just giving aa something to
head towards if kirupa's method was insufficient!

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 03, 2006 May 03, 2006
I know.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2006 May 03, 2006
skinner ( http://www.gskinner.com/blog/archives/2005/10/source_code_sha.html) had the first satisfactory solution to collision detection of irregularly shaped movieclips but it only works when the movieclips have the same parent timeline.

i have a solution that is faster and works in all situations
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2006 May 03, 2006
kglad wrote:
> i have a solution that is faster and works in all situations
>
are you just boasting or were you planning on letting us know what it
is? ;-)

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2006 May 03, 2006
i don't think there's a need for my solution unless someone has trouble with skinner's solution. he published his solution with instructions on its use and he was the first to solve this problem so i think he deserves credit.

the link i posted to skinner's solution contains a link to download the files needed and instructions on the use of his solution.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 03, 2006 May 03, 2006
But, wouldn't that only run in Flash Player 8?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 03, 2006 May 03, 2006
yes, flash player 8 for both solutions.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 04, 2006 May 04, 2006
kglad, the majority of my clients still want me to target Flash Player 7. Now, for some reason, lately a lot of requests for programming are for (simple) games and I had to do some word, math and memory games. But, knowing that eventually a request for a game with (advanced) collision detection and reaction will pop up, I dived into the topic to be prepared. I would use point-2-line collision detection and treat the irregular shape as a set of lines. As far as I can tell this approach works but haven't tested heavily yet. I'm curious: in your opinion, in what sense is Grant's approach 'the first satisfactory solution'?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 04, 2006 May 04, 2006
maybe you can see
www.gskinner.com/blog/archives/2005/10/source_code_sha.html
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2006 May 04, 2006
skinner's was the first hit detection that worked for all (non-rectangular) shapes without requiring shape-specific work-arounds.

it's subjective judgement to say it's satisfactory and other work-arounds are not satisfactory. but i think most people would agree with my judgement.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 04, 2006 May 04, 2006
Get it. Thanks.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 04, 2006 May 04, 2006
kglad wrote:

> the link i posted to skinner's solution contains a link to download the files
> needed and instructions on the use of his solution.
>
you didn't post a link that I can see... although am readin this via
NNTP so maybe it's something that only shows up in the online version?

--
MOLOKO
Macromedia Certified Flash MX 2004 Developer
Macromedia Certified Flash MX Developer
------------------------------------------------
::remove _underwear_ to reply::
'There ain't no devil - it's just God when he's drunk' Tom Waits
------------------------------------------------
GCM/CS/IT/MC d-- S++:- a- C++ U--- P+ L++ !E W+++$ N++ O? K+ w+++$ !O M+
VMS? PS+++ PE- Y PGP+ t+ 5-- X-- R* tv++ b++++ DI++++ D+ G e h-- r+ y++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2006 May 04, 2006
LATEST
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines