Skip to main content
eliw12510111
Participating Frequently
October 4, 2017
Question

Collision detection issues

  • October 4, 2017
  • 1 reply
  • 301 views

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;

        }

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
October 4, 2017

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.