Moving a movieclip in a certain direction

Hi!
So, i got this movie clip (say a military tank), and i have attached to it a missile by script. When the tank moves, the missile moves with it, and when the tank rotates, the missile rotates with it. Now what i want it, when i hit the space button, to shoot the missile in the direction it is pointed to. How can i do this, please? Kindly advice how to do it please.
Here's a video clip of my tank and missle: http://youtu.be/ksA8BM-z4kU
Thanks for any response.
KasunL

if you chose your transform points wisely, you can use the tanks rotation property to direct your missile.  but don't attach to the missile to the tank.  that will be problematic for more than 1 reason.
so you would usually look something like the following in a loop (eg, enterframe) and you may need to adjust the tanks rotation if its default rotation of 0 fails to point towards the position x axis.:
missile.x+=speed*Math.cos(Math.PI*tank.rotation/180);
missile.y+=speed*Math.sin(Math.PI*tank.rotation/180);
eg,
var m:Missile;
var speed:int=whaTEVER;
var tankW:Number = tank.width;
function bF(e:KeyboarEvent):void{
m=new Missile();
this.addChild(m);
m.rotation=tank.rotation;
m.x = tank.x+tankW/2*Math.cos(tank.rotation*Math.PI/180);
m.y = tank.y+tankW/2*Math.sin(tank.rotation*Math.PI/180);
m.addEventListener(Event.ENTER_FRAME,enterframeF);
function enterframeF(e:Event):void{
e.currentTarget.x+=speed*Math.cos(Math.PI*e.currentTarget.rotation/180);
e.currentTarget.y+=speed*Math.sin(Math.PI*e.currentTarget.rotation/180);
if(e.currentTarget.x>stage.stageWidth||e.currentTarget.y>stage.stageHeight||e.currentTarge t.x<0||e.currentTarget.y<0){
this.removeChild(MovieClip(e.currentTarget));
e.currentTarget.removeEventListener(Event.ENTER_FRAME,enterframeF);

Similar Messages

  • Moving a Movieclip towards its rotation?

    Hello!
    Basically, what I'm trying to accomplish is moving a movieclip towards the direction it's facing.
    I've been scoping around the net for different ideas on how to do it, but I've only found AS2 tuts.
    What I've done already is making the movieclip rotate around it's own center when the user presses either the left or the right arrow-key.
    What I'm now trying to accomplish is to make the movieclip move forward to the direction it is currently facing when the user presses up and vice versa for pressing down.
    Any ideas on how to do this?

    Yes this I did understand.
    But, the thing is, when I set these values, the player automatically spawns in the top left corner?
    The thing is.
    I still want the player to spawn in the middle of the screen, whilst allowing the player to rotate and move towards the rotation.
    How would I solve this with a Keyboard Eventlistener?..
    I'm already using a switch(e.keyCode) with the appropriate keyCodes.
    Like so:
    public function keyDownHandler(e:KeyboardEvent):void
    switch(e.keyCode)
    case Keyboard.LEFT: player.rotation -= 5; break;
    case Keyboard.RIGHT: player.rotation += 5; break;
    case Keyboard.UP: player;
    The "update" function is exactly like yours, but the thing it is doing now, is setting the players X value in the top left corner..

  • How to make an object in an area go a certain direction

    As the title states, I'm very curious as to if there's a way to define or mark a certain area, and any objects inside that area go the specified direction. For instance, say there was a conveyor belt in the project. I'd like to mark a square over it and any item that enters the boundaries would start going right at a certain speed.

    Just paste the motion path onto each elements layer. then sequence the layers in time.
    I'm trying to avoid doing another job so I made you an example.  :-)
    Here's the project file
    Dropbox - tanktrack.aep
    For some reason Dropbox is adding a .txt suffix to the end of the filename.  If that happens to you, just delete the .txt from the filename and you should have a CS6 AE project file.

  • Moving a movieclip's location

    let's say i have _level0.box1.ball
    I want to move ball into _level0.box2 so it will become
    _level0.box2.ball
    How do I do this and have ball keep all it's original
    properties?

    I did think about it.
    Part of the way object oriented languages work is that you
    can move objects to different parents when needed. However, the
    movieclip object can't be moved at run time because of it's run
    time usage.
    For example, if you have a deck of cards, you would put 52
    card objects inside of a deck object. Then you can pass the card
    objects to the player objects and to the 'table' object. But if the
    card is always visible on the stage, it's harder to do this because
    you can't change a movieclips location. Sure you can use wannabe
    pointers, but then you get screwed on movie depths because of
    parent movie clips.
    All in all, it's a huge mess and it should be easier, hence
    why I tried to use the forums.

  • Rotate Movieclip depending on its direction its traveling?

    hello, this is prolly a simple question..
    but i need help making my arrow object rotate in the direction its traveling, since  i have gravity on the object..
    my arrow is called ArrowMC.
    anyone?

    This is my code to move the arrow and with gravity. with array
    function UpdateArrow():void
        var TempEnemy:MovieClip;
        for (var ia:int =Arrows.length-1; ia>=0; ia--)
            TempEnemy = Arrows[ia];
         TempEnemy.x+=5;
            //start gravity + collision
            var vyT:Number = 0;
            var GravityT:Number = .5;
            vyT +=  GravityT;
            //GroundObject
            if (! GroundObject.hitTestPoint(TempEnemy.x,TempEnemy.y,true))
                TempEnemy.y +=  vyT;
            for (var i:int=0; i<10; i++)
                if (GroundObject.hitTestPoint(TempEnemy.x,TempEnemy.y,true))
                    TempEnemy.y--;
                    vyT = 0;
    i want the arrow to start rotate down when it comes down to the ground with gravity...
    i tryd TempEnemy.rotation = TempEnemy.direction..
    this dosnt seem to work...

  • Playing a movieClip in a certain x position

    I want to play video clip when it is dragged into the timeline I created. I handled the timeline and drag/drop part but I need that clip to play when button is clicked on. So I need to make my function determine the x position of the movieClip and play it if it is on the certain x value.
    Is this possible?

    No, let me explain. I am creating a timeline for draggable short videos. When they are dragged and snapped into my timeline, and the user clicks on the button, they should start play. I need a function to play the videos according to their x position. But I can't do that because I don't know if it is possible.

  • Picking only works when facing certain directions

    Hi, I'm developing an adventure game in Java3D that involves moving around, picking up items, and using those items with other elements of the scene. Anyway, I'm having a strange problem with picking. I'm using pickCanvas with the mode set to pickBounds, but when I call pickClosest, I don't always get the closest object.
    More specifically, when I am facing the direction I start at in the scene, the picking works fine, but when I am facing the opposite direction, pickClosest seems instead to pick the object that is farthest away from me (from what I can tell when I go through the results of pickAll).
    My movement and rotation code is probably too big to post, but I was wondering if anyone else had any ideas. Is their something about the viewing platform that the PickCanvas doesn't have access to, or is my movement and rotation code not doing something properly? This really has me stumped!

    Finally fixed the problem by using the deprecated PickMouseBehavior class. Is this a bug? (I should have mentioned that I'm using Java 1.3 so that, I'm told, I can use positional sound correctly).

  • Perspective View using orbit tool won't let me rotate in certain directions

    Is the perspective view able to view in all directions and angles? Often when I use it with the orbit tool I can rotate about the X and Y planes but not the Z. Or Z and Y but not X. I was under the impression that the perspective view and the orbit tool would allow you to get any angle/view you wanted. Or perhaps I may be using the orbit tool wrong. But I tried to click and drag in all directions, but is not orbiting in the direction I want.

    Thanks Mark,
    The orbit tool at the top right is not letting me view about an axis. Are you suggesting I hold the command while using the orbit tool as well?
    Also, when you say hold the command and click and drag within the bands in the Canvas, wouldn't this change the orientation of the object or camera? All I want to do is change my perspective view to the angle I want so I can edit 3d motion paths with more precision.

  • Moving many movieclips

    I'm new. I'd like to create a file that has 3 groups of
    movieclips. Group 1 never moves in the users viewport. Whenever
    group 2 moves, group 3 moves as well, but group 3 can also move
    independently. I expect to draw all of the mc's by hand instead of
    with AS, otherwise I would create them all as children of one mc
    and move that. Do I just make 3 groups and move them? Is there a
    way to add movieclips to one big clip after they are already drawn?
    Just looking for advice on the best terms to google to figure out
    how to proceed. Thanks in advance.

    Or should I build three different files and import the output
    swfs into one and set the rules there?

  • Moving Sprite with arrow keys, simultaneous directions

    Hi everyone.
    I'm trying to create a small arcade style game, you control a
    small ship, shoot at incoming targets, try to dogde their shots,
    etc. I'm working on the ship's movement right now, using the arrow
    keys to control it. Getting it to move one direction at a time is
    easy, but sometimes I need to move it diagonally, otherwise I think
    gameplay will suffer considerably.
    I have tried several things but I never seem to be able to
    tell Flash that two keys are being pressed simultaneously. Can
    anyone tell me how I might achieve this?
    Thank you.

    This format should allow detection of multiple keys at once:
    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
    function keyPressed(ev:KeyboardEvent):void {
    var pressedKey:uint = ev.keyCode;
    if(pressedKey == Keyboard.LEFT) {
    leftDown = true;
    if(pressedKey == Keyboard.RIGHT) {
    rightDown = true;
    if(pressedKey == Keyboard.UP) {
    upDown = true;
    if(pressedKey == Keyboard.DOWN) {
    downDown = true;
    ship.addEventListener(Event.EnterFrame, moveShip);
    }

  • Moving a movieclip

    I would like to achieve the following:
    I have an oversized moveclip which i will place on the stage.
    When flash swf  is running, I would like to move the movieclip left, right, up or down when i mousedown. Just like the "MOVE" tool in photoshop.
    Is there a sample.fla on this?

    you can use startDrag(), stopDrag() for this.

  • Fluid Layout - stop changing resize position when movieclip is at certain position

    Hello. I have been trying things out for hours, and I still can't get it.
    I am following this Fluid Layout tutorial: http://active.tutsplus.com/tutorials/web-design/build-a-fluid-website-layout/
    I added a Menu_mc on my stage. Initially, this should be at the center of the stage and when I click on it, it will tween on the upper left corner of the browser. However, when I resize the browser, the Menu_mc goes back to the center of the screen.
    I have tried separating a different actionscript file where it is specifically for initialization of the object and another one for resizing. And then when I call it on my main AS file it goes like this:
    // Add the symbols to stage
                 var Menu_mc = new Menu_MC();
                 addChild(Menu_mc);
                 // Apply the alignment to the middle
                 var Menu_InitParam = {
                     x:0.53,
                     y:0.35,
                     offsetX: -Menu_mc.width/2,
                     offsetY: -Menu_mc.height/2
                 new InitFluidObject(Menu_mc,Menu_InitParam);
                 var Menu_ResizeParam = {
                     x:Menu_mc.x,
                     y:Menu_mc.y,
                     offsetX: -Menu_mc.width/2,
                     offsetY: -Menu_mc.height/2
                 new FluidObject(Menu_mc,Menu_ResizeParam);
    But it seems futile. Could anyone please help? Thanks a lot!

    Do you have any useful resources that I could perhaps check out? Haven't explored ANY javascript before =)

  • Trouble with Bluetooth Devices

    I have a MacBook Pro 13" from late-2011.  Recently I have decided to use Bluetooth headsets instead of wired earbuds because I tend to forget they are in my ears and when I get up, they are yanked out of my ears, hurting me and potentially pulling my notebook off of something.  I had an LG Tone before getting my current Motorola S11-FLEX HD headset.  I switched because of the problems I have been having with Bluetooth but switching has not solved the issue.
    My biggest problem with my Bluetooth headsets is that the audio stutters and then de-syncs with any video.  The de-sync can be as bad as a full second.  I'll see the video's actions before I hear them.  The de-sync also affects the responsiveness of controls.  After I give a command, the audio will continue to play for however long the de-sync is before the command is performed.  It's like it's making up for the lost time.  The only solution I have come across is turning off the device, then turning it back on but that only works some of the time.  Usually, I have to turn it off and then on again two or three times before the de-syncing issue disappears.  I have no idea the cause as my LG Tone works to specifications with devices that belong to other people.  I have found that moving my head in a certain direction will cause the de-sync.  Sometimes, it's leaning back; other times, it's tilting my head.  It's as if the Bluetooth field is planar and I'm jumping out of the plane.
    Another issue is the distance I can be from my device.  My Bluetooth headsets boasts being able to function perfectly as far as 30 feet for one headset but moving even 5 feet will cause the previously mentioned de-syncing if the audio is playing.  If I pause the audio, I can move about 10 feet.  After I move 10 feet, when I press play, the de-sync appears.  It renders the function of being wireless to being useless.  I wanted to Bluetooth so I didn't have to pause, take off my device, do what I need to do, and before coming back, putting on the device, and resuming play, hoping that nothing has gone wrong to cause a de-syncing issue.
    A third issue I have is that sometimes, while listening to some audio of some kind, another program will make a noise causing the audio to cut out.  My notebook or the web browser is not aware that audio is no longer playing.  It's as if the new program has muted the original audio.  The only cure: turning off the device and turning it on again and hoping it's working.
    The last issue I can think of is that when I turn my notebook off for any reason, all Bluetooth devices are forgotten causing me to go through the hassle of repairing the devices again but many times, the repairing process fails and despite being on and not paired to anything else, my notebook is unable to pair unless I turn both the device off and my notebook's Bluetooth off before turning both back on.
    Has anyone run into issues like this? If so, does anyone have any recommendations on how to correct the problem? The problem is on my notebook side as the devices work fine with other products.  The LG Tone could be used across the house when it was attached to my father's Kindle Fire and when attached to my iPhone 5, I could walk 20 feet with doors and concrete between me and the device before any issues began (both devices had trouble with my iPhone but pausing usually fixes the issue so I don't care).  Please, I need some advice and help.

    Some details missing.
    I have a Pioneer DEH-P7000BT. On telephone settings, everything OK.
    When I want to sync to my Audio Bluetooth, I hear the sound in slow motion :-)
    I have to delete the Bluetooth device on the radio, and re-syncing on Audio Devices and everything fine.
    Same thing all the time.
    When I had iOS 3.1.3 on my iPhone 3G, everything was OK.
    I can't find Firmware Update for my radio.

  • How to stop a movie clip moving

    I'm not newbie to flash but I am newbie to coding using
    actionscript!!!
    I am trying to create a button that moves a movie clip
    ("content1") diagonally across the screen but once the movie clip
    reaches a certain x co-ordinate I want it to stop and then when I
    click another button I would like it to return to it's starting
    position. At the moment the movie clip moves if I click one of the
    buttons but as soon as I click another one it stops which it
    shouldn't it should go back in the other direction. The other
    problem is that once I've clicked a button I cant seem to get it to
    stop moving once it reaches a certain _x position it just keeps on
    moving off the stage.
    Below is the script I have so far not including any
    conditions to check if "content1" has reached it _x position
    Could anyone help please!!!!
    //on Right movie clip containing the button
    onClipEvent (enterFrame) {
    _root.content1._x += speedX;
    _root.content1._y -= speedY;
    //on Right button inside movie clip
    on (press) {
    speedX = 5.5;
    speedY = 1.33;
    //on Left movie clip containing the button
    onClipEvent (enterFrame) {
    _root.content1._x += speedX;
    _root.content1._y -= speedY;
    //on Left button inside movie clip
    on (press) {
    speedX = 5.5;
    speedY = 1.33;

    Many thanks ClBeech!!!
    I've tried the code you suggested but it doesn't seem to work
    :0(
    I'm working on a Mac using Flash Pro 8 which only has the
    option to publish as 'actionscript 1.0 or 2.0' is the script you
    supplied an actionscript 3.0?
    Below is the script with the amendments, I've changed my
    button instance names to match the script you supplied (left_btn /
    right_btn)
    stop();
    import mx.transitions.Tween;
    import mx.transitions.easing.Strong;
    var rposX = 369;
    //the ending x of the right position
    var rposY = 84;
    //the ending y of the right position
    var lposX = 116;
    //the ending x of the left position
    var lposY = 154;
    //the ending y of the left position
    right_btn.onPress = function() {
    new Tween(content1, '_x', Strong.easeOut, content1._x,
    rposX, time, false);
    new Tween(content1, '_y', Strong.easeOut, content1._y,
    rposY, time, false);
    left_btn.onPress = function() {
    new Tween(content1, '_x', Strong.easeOut, content1._x,
    lposX, time, false);
    new Tween(content1, '_y', Strong.easeOut, content1._y,
    lposY, time, false);

  • Bigger "step" when moving bd stuff with arrows

    Sometimes I will make something like a loop considerably smaller and now I want to move things outside the loop directly to the left/right. I will highlight everything and use the arrow keys which automatically shortens the wires as things move (I believe) and doesn't just tuck the "excess" behind other objects. However, using these arrows the bd stuff moves in very small steps. Is there a way to make it shift in larger steps? Sort of the LabVIEW equivalent of pressing arrows in text editors moves your cursor letter by letter, but certain key combinations can move the cursor to the end of the word, or line.Or is my best bet to highlight, drag with the mouse, then use up/down arrows to straighten anything out that may have become bent?
    CLA, LabVIEW Versions 2010-2013

    smercurio_fc wrote:
    The information is also in the LabVIEW Help: Moving Objects.
     well, i certainly hit the lazy button on this one. I'll take full blame for that. Good deal though, thanks.
    CLA, LabVIEW Versions 2010-2013

Maybe you are looking for

  • GPO with a startup script is not working.

    I have a GPO that I have added a ".bat" script to the "Computer Configuration\Windows Settings\scripts\startup/shutdown" section. The batch file is located in the netlogon folder. This script was part of another Old GPO that I want to consolidate int

  • Re: Using Variables with SWFLoader?

    PkRtc, Try something like the following: <mx:SWFLoader source="app.swf?fName=Mysterious&lName=Stranger&age=32&favoriteColor=haloOrange" />

  • Jco connections Logical System

    Hi All i have a problem with Jco destinations--the logical systems. -->For META DATA i have used one userid and for MODELDATA i have used another user id. -->When accessing the RFC from SAP Webdynpro am using another userid to get connect to R/3 syst

  • Why does my tool box move up so I can not use it?

    WHY DOES MY TOOL BOX ALL OF A SUDDEN TODAY MOVE UP SO i CAN NOT SEE IT OR USE IT? ALSO i CAN NOT SEE MY BOTTOM TOOL BOX EITHER. WHAT CAN i DO TO CHANGE IT BACK OR DO YOU HAVE TO?

  • How to in put "@" on a Spanish key board

    Any one got any idear how to in put "@" on a Spanish keyboard or where I can find it? Ta