The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

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.

    _root.onEnterFrame = function()
          move tank down;
          move tank up;
          move tank left;
          move tank right;
          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.

    // Case in point
       // 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;
    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:

    _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
    tank._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 Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012