1 Reply Latest reply on Sep 30, 2011 4:47 AM by Ned Murphy

    Help, making character attack

    kallekallekutta

      Hello, Im trying to make my character attack, the attack animation is inside the character movie clip on frame 4. But i dont understand how to do it? I want him to attack once, if SPACE is pressed.

       

      I have tried this:

       


      if(Key.isDown(Key.SPACE)){

      this.gotoAndStop(4);

       

       

       

      Heres my code on my Characters MovieClip

       

       

       

       

       

      onClipEvent (load) {

          gravity = 10;

          scale = _xscale;

          walkSpeed = 6;

          maxjump = 0.2;

       

       

      }

      onClipEvent (enterFrame) {

          if (air == true) {

              _y += gravity;

              state = 3;

       

              }

       

          if (Key.isDown(Key.LEFT) && !_root.leftbound.hitTest(_x, _y, true)) {

              _x -= walkSpeed;

              _xscale = -scale;

          }

          if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {

              _x += walkSpeed;

              _xscale = scale;

          }

          if (_root.ground.hitTest(_x, _y, true)) {

              air = false;

          } else {

              air = true;

          }

          if (Key.isDown(Key.UP) && jump == true) {

              _y -= jumpSpeed;

       

          }

          if (air == false) {

              jump = true;

              jumpcount = 0;

              jumpSpeed = 22;

          }

          if (Key.isDown(Key.UP)) {

              jumpcount += 1;

          }

          if (jumpcount>maxjump && jumpSpeed>-2) {

              jumpSpeed -= 2;

          }

          if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {

              state = 1;

          }

          if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {

              state = 2;

          }

          if (!Key.isDown(65)) {

              gotoAndStop(state);

          }

          _root.statetxt = state;

                  }

       

       

      onClipEvent (keyUp) {

          if (Key.getCode() == 83) {

              jump = false;

          }

      }

        • 1. Re: Help, making character attack
          Ned Murphy Adobe Community Professional & MVP

          The code you showed for the SPACE key should work.  If you try it alone in place of all the code you show you should see it gotoAndStop(4).  If it doesn't go, then it is possible some other code you have is forcing it to do something else.  If the problem is that it goes to 4 but never leaves, then you need to add that in as an else condition.