all groups > flash actionscript > december 2004 >
You're in the

flash actionscript

group:

collision detection


collision detection zcan
12/27/2004 9:04:53 PM
flash actionscript: I'm looking for a good tutorial or the basic code using collision detection
for a driving game. Any help is appreciated.

Re: collision detection NSurveyor
12/28/2004 3:22:53 AM
ccar = instanceNameOfYourCar;
road = instanceNameOfYourRoad;
ccar.onEnterFrame = function(){
if(this.hitTest(road)){
//COLLISION!!!!
//Code for what happens on collision
}
}
Re: collision detection David Stiller
12/28/2004 9:22:56 AM
Be aware, there are two ways to use the MovieClip.hitTest() method.
According to the ActionScript dictionary ...

my_mc.hitTest(x:Number, y:Number, shapeFlag:Boolean) : Boolean
my_mc.hitTest(target:Object) : Boolean

.... the second usage, already posted, evaluates the bounding boxes of the
movie clips in question. This means that an intersection might occur even
if the car is not visually touching the road (the bounding box on a curved
bit of road, will, of course, be a rectangle).

Kirupa.com has all kinds of helpful tutorials. Here are examles of
simple and advanced collision detection.

http://www.kirupa.com/developer/actionscript/hittest.htm
http://www.kirupa.com/developer/actionscript/advanced_collision.htm


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

AddThis Social Bookmark Button