Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 11 of 11

Thread: tank shooting/moving

  1. #1

    tank shooting/moving

    ok! So I have a rotating barrel (or what it's called), and the basic for the shooting. But I can't get the tank to move, because then the barrel wont rotate/shoot. The barrel and the body of the tank are seperate MC's.
    My question: How do I make the tank move at the same time as you can move the barrel?

    Then I have a few more questions, but this is the most urgent.

    Hope you understand what I am trying to say

  2. #2
    Instead of using else if's to test your keyPresses... I would suggest using on if statements.

    Code:
    _root.onEnterFrame = function()
    {
       if(Key.isDown(Key.DOWN))
       {
          move tank down;
       }
       if(Key.isDown(Key.UP))
       {
          move tank up;
       }
       if(Key.isDown(Key.LEFT))
       {
          move tank left;
       }
       if(Key.isDown(Key.RIGHT))
       {
          move tank right;
       }
       if(Key.isDown(Key.SPACE))
       {
          have tank shoot;
       }
        // and so on and so forth....
    }
    aiMarz : v. 11.34c - Current Version

  3. #3
    yeah, I've tried that, but I want the barrel to move after the mouse.

  4. #4
    And your point is? As long as you have an if statement with the arrow keys, putting in a mouse location and pointing the barrel towards the mouse is easy.

    ._xmouse and ._ymouse is the location of your mouse's pointer on the screen. Use those along qwith trigonometry and put the results in the onEnterFrame. And you'll be fine.
    aiMarz : v. 11.34c - Current Version

  5. #5
    Yes... But I can't make the tank move at the same time as the barrel is moving...
    The barrel is one MC and the tank is one. How do I attach them to eachother so that the mouse pointing thing wticks with the tank.... It's hard to explain, when I get home, I can post the .fla

  6. #6
    Simple enough.... The base of each MC willl stay together. Your barrel should pivot around one point and that point should be the x and y coordinates of your tank + or - some pixels here and there. So everytime the player moves the tank, he also moves the turret.

    Code:
    // Case in point
    
    if(Key.isDown(Key.DOWN))
    {
       // move tank down
    }
    
    // blah blah blah....
    
    turret._x = tank._x;
    turret._y = tank._y;
    Then you will only have to worry which direction the barrel is facing. Which if you draw it correctly, can be determined by the ._rotation property.
    aiMarz : v. 11.34c - Current Version

  7. #7
    You can also make a function that rotates MC's to the mouse or wuteva else u want them to:

    function pointAt(ob, x, y,offset){
    var dx = x - ob._x;
    var dy = y = ob._y
    var dist = Math.sqrt(dx*dx+dy*dy)
    var angle;
    if(dy<0){
    angle = Math.PI*2-Math.acos(dx/dist);
    } else {
    angle = Math.acos(dx/dist);
    }
    ob._rotation = angle*180/Math.PI+offset;
    }

    put this in the first frame of your movie, then in the tank barrel add:

    onClipEvent(enterFrame){
    _root.pointAt(this, _root._xmouse, _root._ymouse, *wuteva the offset is*);
    }

    *offset depends on how you drew tank barrel, for example, if tank rotation is off by 90 degrees, add 90 in that field*

  8. #8
    yeah, thanks, but I already have the rotation for the barrel and the movement for the tank... It's just that the barrel and the tank are seperate MC's, so the tank moves, but the barrel stays I'm looking for a way to make the Barrel MC and the tank MC stuck to eachother... If you understand what I mean... Thanks for the help though

  9. #9
    add in on ur tank
    if(key.isDown(Down)){
    tank._y+= wuteva
    turret._y+=wuteva
    }

    and do that for all ur movements. I had the same prob, the call to put the turret on the tank comes after the call to move it, which causes the turret to lag. If thats wut ur talking about

  10. #10
    I would have personally put the turret movieclip inside of the tank movieclip.

    _root.tank.turret._rotation = blah blah;

    That will only rotate the turret, but if you were to do this :

    _root.tank._x += 5;

    It would move the tank and the turret.
    aiMarz : v. 11.34c - Current Version

  11. #11
    i use that code for moving my character marz, but when i say move and it palys animation_1 and press attack and it plays fight animation, it gets confused? is there a way to specify to do the attack one above all the others?

    and when pressing multiple keys it has issues with my key releaseing code to stop the anmations playing. could you post the code for key ups that you would use?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012