ForumsProgramming Forumneed help with collision

11 3886
Samurai7x
offline
Samurai7x
64 posts
Nomad

how do i use code to figure out if a collision is happening

  • 11 Replies
anatolytt
offline
anatolytt
64 posts
Peasant

Something is wrong with my head today xD The link is here

dank
offline
dank
983 posts
Peasant

It depends on the version your using.

AS2:
public hitTest(x:Number, y:Number, [shapeFlag:Boolean]):Boolean

AS3:
public function hitTestPoint(x:Number, y:Number, shapeFlag:Boolean = false):Boolean

PixelSmash
offline
PixelSmash
566 posts
Nomad

And while Dank very neatly pointed out the testing against a certain point (which is useful as well, don't get me wrong!) I get the idea you're looking for a collision between two objects - which is both in as2 and as3 something like this:
mc1.hitTest(mc2); (as2)
mc1.hitTestObject(mc2); (as3)

Samurai7x
offline
Samurai7x
64 posts
Nomad

thx alot i appreciate it

SB0202022
offline
SB0202022
3 posts
Nomad

Could someone explain the collision code to me?

PixelSmash
offline
PixelSmash
566 posts
Nomad

Which code exactly, SB? >.>"

clipmaster3
offline
clipmaster3
104 posts
Nomad

well that's all fine and dandy code dank and pixelsmash but that will only check collisions of the bounding boxes... so if you have 2 circles (or anything else non-rectangular for that matter) colliding it will detect collisions where there very clearly is none. There's a nice workaround posted here:
http://troygilbert.com/2007/06/pixel-perfect-collision-detection-in-actionscript3/

Samurai7x
offline
Samurai7x
64 posts
Nomad

how can you make a movie clip change when collision happens?

No_Thumbs
offline
No_Thumbs
20 posts
Nomad

there are many different ways to do this

one is to edit mc1 so it has 2 frames in it each with different image. then add stop(); to the first frame in mc1. then when i collides with mc2 add this code.

mc1.gotoAndStop(2);

Samurai7x
offline
Samurai7x
64 posts
Nomad

so it would be like
{
mc1.hitTest(mc2);
mc1.gotoAndStop(2);
}
?

No_Thumbs
offline
No_Thumbs
20 posts
Nomad

yes

Showing 1-11 of 11