7 Replies Latest reply: Mar 6, 2012 7:09 AM by kglad RSS

    Bullets Only Shoot 1 way???

    LukeElChul Community Member

      this is in my bullet movie clip on the timeline.

       

      _root.bulletArray.push(this)

      speed=12

      _root.shootable=false

      _rotation=_root.Dip._rotation

      onEnterFrame=function(bullet){

                if(_x>550){

                          removeMovieClip(this)

                }else if(_x<0){

                          removeMovieClip(this)

                }else if(_y>400){

                          removeMovieClip(this)

                }else if(_y<0){

                          removeMovieClip(this)

                }

                _x+=Math.cos(_rotation*Math.PI/180)*speed

      }

       

       

      this is on the main timeline.

       

      bulletArray = new Array()

      Bullets = 0;

       

      function shoot(){

                 var Bullet = attachMovie("Meteor", "Meteor"+Bullets, _level0.getNextHighestDepth(), {_x:Dip._x, _y:Dip._y});

      }

       

      This is the script in my character.

       

      onClipEvent (load) {

                gravity = 12;

                walkSpeed = 3;

                maxJump = 15;

                scale = _xscale;

      }

      onClipEvent (enterFrame) {

                if (Key.isDown(Key.LEFT)) {

                          _xscale = -scale;

                          _x -= walkSpeed;

                          _root.Dip.Dip1.gotoAndStop(2)

                }

                if (Key.isDown(Key.RIGHT)) {

                          _xscale = +scale;

                          _x += walkSpeed;

                          _root.Dip.Dip1.gotoAndStop(2)

                }

                if (air == true) {

                          _y += gravity;

                          state = 3;

                }

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

                          air = false;

                } else {

                          air = true;

                }

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

                          _y -= jumpSpeed;

                }

                if (air == false) {

                          jump = true;

                          jumpcount = 1;

                          jumpSpeed = 30;

                }

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

                          jumpcount += 1;

                          jump = false

                }

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

                          _root.shoot()

                }

      }

      onClipEvent (enterFrame) {

                if (this._x>=550) {

                          this._x = 545;

                }

                if (this._x<=10) {

                          this._x = 15;

                }

      }

       

      It all works but when i turn around it still shoots the same way im sure its something simple but i just cant work it out.

        • 1. Re: Bullets Only Shoot 1 way???
          kglad MVP

          _root.Dip is determining the direction your bullets shoot.  what is that?

          • 2. Re: Bullets Only Shoot 1 way???
            LukeElChul Community Member

            Dip is my player

            • 3. Re: Bullets Only Shoot 1 way???
              kglad MVP

              then try:

               

               

               

               

              this is in my bullet movie clip on the timeline.

               

              _root.bulletArray.push(this)

              speed=12

              _root.shootable=false

              //_rotation=_root.Dip._rotation

              onEnterFrame=function(bullet){

                        if(_x>550){

                                  removeMovieClip(this)

                        }else if(_x<0){

                                  removeMovieClip(this)

                        }else if(_y>400){

                                  removeMovieClip(this)

                        }else if(_y<0){

                                  removeMovieClip(this)

                        }

                        _x+=Math.cos(_rotation*Math.PI/180)*speed

              }

               

               

              this is on the main timeline.

               

              bulletArray = new Array()

              Bullets = 0;

               

              function shoot(){

                         var Bullet = attachMovie("Meteor", "Meteor"+Bullets, _level0.getNextHighestDepth(), {_x:Dip._x, _y:Dip._y});

              Bullet._rotation=Dip._rotation

              }

               

              This is the script in my character.

               

              onClipEvent (load) {

                        gravity = 12;

                        walkSpeed = 3;

                        maxJump = 15;

                        scale = _xscale;

              }

              onClipEvent (enterFrame) {

                        if (Key.isDown(Key.LEFT)) {

                                  _xscale = -scale;

                                  _x -= walkSpeed;

                                  _root.Dip.Dip1.gotoAndStop(2)

                        }

                        if (Key.isDown(Key.RIGHT)) {

                                  _xscale = +scale;

                                  _x += walkSpeed;

                                  _root.Dip.Dip1.gotoAndStop(2)

                        }

                        if (air == true) {

                                  _y += gravity;

                                  state = 3;

                        }

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

                                  air = false;

                        } else {

                                  air = true;

                        }

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

                                  _y -= jumpSpeed;

                        }

                        if (air == false) {

                                  jump = true;

                                  jumpcount = 1;

                                  jumpSpeed = 30;

                        }

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

                                  jumpcount += 1;

                                  jump = false

                        }

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

                                  _root.shoot()

                        }

              }

              onClipEvent (enterFrame) {

                        if (this._x>=550) {

                                  this._x = 545;

                        }

                        if (this._x<=10) {

                                  this._x = 15;

                        }

              }

               

              It all works but when i turn around it still shoots the same way im sure its something simple but i just cant work it out.

              • 4. Re: Bullets Only Shoot 1 way???
                prodigalmaster Community Member

                Oh wow.. kglad ive had to work around that for a long time... im so bad at cosine and sine and angles.. wish I know that before, thank you so much man!

                • 5. Re: Bullets Only Shoot 1 way???
                  kglad MVP

                  you're welcome.

                   

                  you should work on moving all code from objects to timelines (or classes).  but moving code from objects to timelines is a pretty easy transition and makes your code much easier to debug, maintain and extend.

                  • 6. Re: Bullets Only Shoot 1 way???
                    LukeElChul Community Member

                    Thanks That all worked

                    • 7. Re: Bullets Only Shoot 1 way???
                      kglad MVP

                      you're welcome.

                       

                      p.s. please mark correct/helpful responses.