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

Collision detection issues

Community Beginner ,
Oct 04, 2017 Oct 04, 2017

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;

        }

TOPICS
ActionScript
283
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 ,
Oct 04, 2017 Oct 04, 2017
LATEST

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.

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