Copy link to clipboard
Copied
I'm creating a space game where the main player unit is a stationary object that fires a laser.
I've added planets to the environment and want the lasr to 'break' on contact with the planets.
So far everything works, but the laser is breaking on a box surrounding each planet and not the planets themselves.
I think the issue is here on my checkCollisions function.
private function checkCollisions(testX:Number, testY:Number):Boolean
{
var i:int;
var len:int = _planets.length;
for (i = 0; i < len; i++)
{
if (MovieClip(_planets).hitTestPoint(testX, testY, true))
{
return true;
break;
}
}
return false;
}
Copy link to clipboard
Copied
if your planets (and laser 'bullets') are round you can check if the distance between the two and if that's less than the sum of their radii you can initiate your 'break' animation.
otherwise, you can use a bitmapdata hittest for a true shape-based hittest.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now