Skip navigation
Currently Being Moderated

Bullets Only Shoot 1 way???

Mar 4, 2012 7:47 AM

Tags: #help #flash #frame #swf #dynamic #as2 #play #actionscript #game #movie #clip #2.0 #objects #movie_clip #dinamyc

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.

 
Replies
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 4, 2012 8:02 AM   in reply to LukeElChul

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

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 4, 2012 8:37 AM   in reply to LukeElChul

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 4, 2012 1:08 PM   in reply to kglad

    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!

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 4, 2012 3:40 PM   in reply to prodigalmaster

    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.

     
    |
    Mark as:
  • kglad
    72,189 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 6, 2012 7:09 AM   in reply to LukeElChul

    you're welcome.

     

    p.s. please mark correct/helpful responses.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points