A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Gun direction

  1. #1
    Senior Member
    Join Date
    Jan 2005
    Posts
    117

    Gun direction

    My other thread didnt attract you, so maybe this will.i want my tank's machine gun to point where the mouse is. i have this code on first frame of _root timeline, and check out the source to see what i mean. it doesnt work. anyone know how to fix it? thanks.


    Code:
    mousex = _xmouse;
        mousey = _ymouse*-1;
        angle = Math.atan(mousey/mousex)/(Math.PI/180);
        if (x<0) {
            angle += 180;
        }
        if (x>=0 && y<0) {
            angle += 360;
        }
        _root.tank.mgun._rotation = angle;
    Attached Files Attached Files

  2. #2
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    Flash does weird things with that code when placed directly on the Movie Clip you're trying to rotate. You need a second MC to hold the code. Look carefully at your tank MC near the machine gun and you'll find the anglefinder MC to make this thing work. Also, your code itself needed a little tweaking.

    Here's the fixed .fla:
    Attached Files Attached Files

  3. #3
    Senior Member
    Join Date
    Jan 2005
    Posts
    117
    hey thanks alot, my other question was how do i make a bullet come out facing the right way and heading the right way? I have my other thread below this one

  4. #4
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    There is a tutorial for that on www.actionscript.org in the Advanced Tutorial section. Hope that helps.

  5. #5
    Senior Member
    Join Date
    Jan 2005
    Posts
    117
    thanks

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center