6 Replies Latest reply on Apr 18, 2009 1:42 PM by kglad

    Particle System Collision Area?

    shintashi Level 1

      so I've got a bunch of modules called "c4" labled red1,red2,red3, etc. And a laser made from particles, with angle controlled
      by bckspace and enter keys:

       


      onEnterFrame = function(){

       


      for (m=1;m<4;m++){
      c4 = this["red"+m];  

       

       

       

      if(robot_mc.laser_mc.lasereye_mc.hitTest(c4.cap)){c4.gotoAndPlay("frame2"); }

       

       

       

          //laser controls
          if(Key.isDown(Key.BACKSPACE)){robot_mc.laser_mc._visible = true; robot_mc.laser_mc.lasereye_mc._rotation -= 7;}
          if(Key.isDown(Key.ENTER)){robot_mc.laser_mc._visible = true; robot_mc.laser_mc.lasereye_mc._rotation += 7;}
          if(!Key.isDown(Key.BACKSPACE) && !Key.isDown(Key.ENTER)){robot_mc.laser_mc._visible = !true;}

       

       

       

       

       

          }

       

       

       

       

       


      for(i=0;i<500;i++) {
          photons = this["photon"+i];   
          var k:MovieClip = robot_mc.laser_mc.lasereye_mc.attachMovie("photon","photon"+i ,robot_mc.laser_mc.lasereye_mc.getNextHighestDepth());
              k._xscale = Math.random()* 120 - 20;
          k._yscale = Math.random()* 180 + 35;
          k._y -= Math.random()* 10 +10;             //plus changes distance of start of beam, base changes range
              k.gotoAndPlay(Math.ceil(Math.random()*16));    }

       

       

       


      The problem I run into is having the collision work with the beam, as opposed to the bounding box that begins with the
      lasereye_mc. Is there a way to get the c4 to react with the beam, instead of the bounding box around the beam? Or a way to get the photons to interact individually? Also, is there a way to load a particle system through an onEnterFrame without it overloading/oversaturting ?    Thanks.

        • 1. Re: Particle System Collision Area?
          kglad Adobe Community Professional & MVP

          there are several ways to handle this, but the easiest is to keep track of those photons that are on-stage, remove the ones that are not on-stage and use a hitTest on each of the existing photons.  that will solve a number of problems that you are encountering or will encounter.

          • 2. Re: Particle System Collision Area?
            shintashi Level 1

            "the easiest is to keep track of those photons that are on-stage"

            what do you mean keep track?

             

             

             

            "remove the ones that are not on-stage"

            that's precisely what I do not know how to do. I have been unable to effect the particles of a particle system on an individual basis.

             

            "and use a hitTest on each of the existing photons".

            My previous attempt to place a for - loop inside another for loop failed. The particles still appeared but the collision detection was nonexistent.

            • 3. Re: Particle System Collision Area?
              kglad Adobe Community Professional & MVP

              i don't see where you're updating the photons position so i assume you're using timeline animation to move the photons.  if that's true, place the following on the last frame of the photon's timeline:

               

              this.removeMovieClip();

               

              and loop through all the children of the photon's parent movieclip using them in your hittest.

              1 person found this helpful
              • 4. Re: Particle System Collision Area?
                shintashi Level 1

                ok, so I added the remove movieclip at the end of the particle timeline,

                 

                and then cut down the i<500 to i<80, and added the c4.cap hitTest;

                 

                 

                 

                for(i=0;i<80;i++) {
                    photons = this["photon"+i];   
                    var k:MovieClip = robot_mc.laser_mc.lasereye_mc.attachMovie("photon","photon"+i ,robot_mc.laser_mc.lasereye_mc.getNextHighestDepth());
                        k._xscale = Math.random()* 120 - 20;
                    k._yscale = Math.random()* 220 + 35;

                    k._y -= Math.random()* 15 + 10;             //plus changes distance of start of beam, base changes range

                        k.gotoAndPlay(Math.ceil(Math.random()*16));   
                            for (m=1;m<4;m++){
                        c4 = this["red"+m];   
                    if(c4.cap.hitTest(k)){c4.gotoAndPlay("frame2"); }
                   
                            } //end c4 for loop
                   
                    } // end photon for loop

                 

                    }

                 

                and duplicated the loop for the c4 module. It now works like a charm ^_^

                 

                Thanks much!

                • 5. Re: Particle System Collision Area?
                  shintashi Level 1

                  kglad solved the problem with the removemovieclip solution inside the particle's timeline, and the for loop inside the second for loop only needed slight modification.

                  • 6. Re: Particle System Collision Area?
                    kglad Adobe Community Professional & MVP

                    you're welcome.