How to stop my character of shooter every time he turns... (?)

Greetings;

I just worked with AS3 for two weeks (before that I only did starting from simple animations in a FLA). In any case, I have the origins of a game I've been working on... a stick figure moving with the arrow keys, shoots through the space bar and turns with the keys A and D. The problem is he doing involuntarily whenever I have run with the keys A and D. I think it's because x and is given to the "missles" speeds are functions (sin / cos) of the player.rotation.

Is there another way to program it so that it does not pull when it runs?

Thank you

Jeremy

SWF:

http://theVue.com/Jeremy/ideas/schoolOfFish.swf

Main.As:

package

{

import flash.display.MovieClip;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.geom.Rectangle;

import flash.events.KeyboardEvent;

import flash.ui.Keyboard;

/public class Main extends MovieClip

{

/ / declare variables:

var fishMov:FishMov;

var fishMov1:FishMov;

var fishMov2:FishMov;

var: ceiling;

var player: Player;

var missle1:Missle;

var missle2:Missle;

var missle3:Missle;

var missle4:Missle;

var missleStartPoint = MissleStartPoint;

var vx = 0;

var vy = 0;

var ax = 0;

ay var = 0;

vx1 var = 0;

vy1 var = 0;

var ax1 = 0;

ay1 var = 0;

var vx2 = 0;

var vy2 = 0;

var: ax2 = 0;

ay2 var = 0;

var playervx = 0;

var playervy = 0;

var playeray = 0;

var missle1vx = 0;

var missle1vy = 0;

var missle2vx = 0;

var missle2vy = 0;

var missle3vx = 0;

var missle3vy = 0;

var missle4vx = 0;

var missle4vy = 0;

var missleCounter = 1;

//

//running the program using Main.as

public void Main()

{

//attaching movieclip classes to instances:

fishMov = new FishMov;

fishMov1 = new FishMov;

fishMov2 = new FishMov;

ceiling = new ceiling;

player = new player;

missle1 = new missile;

missle2 = new missile;

missle3 = new missile;

missle4 = new missile;

//adding instance to the display list:

for (var i = 1; i < 5; i ++)

{

addChild (this ["missle" + i]);

this ['missile' + i] .x = - 100;

this ['missile' + i] = - 100 there.

this ['missile' + i] .height = 30;

this ["missile" + i] .width = 30;

}

addChild (fishMov);

fishMov.x = stage.stageWidth/2-100;

fishMov.y = stage.stageHeight/2-120;

fishMov.width = 999/10;

fishMov.height = 700/10;

addChild (fishMov1);

fishMov1.x = stage.stageWidth/2-100-150;

fishMov1.y = stage.stageHeight/2-120 + 150;

fishMov1.width = 999/10;

fishMov1.height = 700/10

addChild (fishMov2);

fishMov2.x = stage.stageWidth/2-100 + 150;

fishMov2.y = stage.stageHeight/2-120 + 300;

fishMov2.width = 999/10;

fishMov2.height = 700/10

addChild (ceiling);

ceiling.width = stage.stageWidth;

addChild (player);

player.x = 50;

player.y = stage.stageHeight/2 + 300;

player.height = 50;

player.width = 80;

player.rotation = 0;

//function formless for missleDisappear():

function missleReset (): void

{

missle1vx = 0;

missle1vy = 0;

missle2vx = 0;

missle2vy = 0;

missle3vx = 0;

missle3vy = 0;

missle4vx = 0;

missle4vy = 0;

}

//function formless for missleLaunch():

function missleLaunch (): void

{

if (missleCounter == 5)

{missleCounter = 1 ;}

var missleCosFactor = Math.cos((player.rotation/180)*Math.PI);

var missleSinFactor = Math.sin((player.rotation/180)*Math.PI);

if (missleCounter == 1)

{

missle1.x = player.x;

missle1.y = player.y;

missle1.alpha = 100;

missle1vx = 20 * missleCosFactor;

missle1vy = 20 * missleSinFactor;

}

if (missleCounter == 2)

{

missle2.x = player.x;

missle2.y = player.y;

missle2.alpha = 100;

missle2vx = 20 * missleCosFactor;

missle2vy = 20 * missleSinFactor;

}

if (missleCounter == 3)

{

missle3.x = player.x;

missle3.y = player.y;

missle3.alpha = 100;

missle3vx = 20 * missleCosFactor;

missle3vy = 20 * missleSinFactor;

}

if (missleCounter == 4)

{

missle4.x = player.x;

missle4.y = player.y;

missle4.alpha = 100;

missle4vx = 20 * missleCosFactor;

missle4vy = 20 * missleSinFactor;

}

}

addEventListener (Event.ENTER_FRAME, onEnterFrame)

int onEnterFrame(event:Event):void

{

missle1.x += missle1vx;

missle1.y += missle1vy;

missle2.x += missle2vx;

missle2.y += missle2vy;

missle3.x += missle3vx;

missle3.y += missle3vy;

missle4.x += missle4vx;

missle4.y += missle4vy;

/ / x speed control

player.x += playervx;

if (playervx > 2)

{playervx = 2 ;}

if (playervx <-2)

{playervx = - 2 ;}

/ / y: speed control

player.y += playervy;

if (playervy > 2)

{playervy = 2 ;}

if (playervy <-2)

{playervy = - 2 ;}

/ / friction in x and y:

& playervx =-0.02 * playervx;

& playervy =-0.02 * playervy;

fishMov.fish.y += vy;

fishMov1.fish.y += vy1;

fishMov2.fish.y += vy2;

vx += ax;

vy += ay;

vx1 += ax1;

vy1 += ay1;

vx2 += ax2.

vy2 += ay2;

playervy += playeray;

if (fishMov.fish.hitTestObject (ceiling))

{

fishMov.fish.y += ceiling.height;

}

if (missle1.hitTestObject (ceiling))

{

missle1vy = - missle1vy;

}

if (missle2.hitTestObject (ceiling))

{

missle2vy = - missle2vy;

}

if (missle3.hitTestObject (ceiling))

{

missle3vy = - missle3vy;

}

if (missle4.hitTestObject (ceiling))

{

missle4vy = - missle4vy;

}

if (missle1.missleCircle.hitTestObject (fishMov.fish))

{

fishMov.fish.fish_gr.gotoAndStop (2);

= missle1.x missle1.y = - 100;

missle1.alpha = 0;

ay += 5;

vx = vy = 10;

}

if (missle2.missleCircle.hitTestObject (fishMov.fish))

{

fishMov.fish.fish_gr.gotoAndStop (2);

= missle2.x missle2.y = - 100;

missle2.alpha = 0;

ay += 5;

vx = vy = 10;

}

if (missle3.missleCircle.hitTestObject (fishMov.fish))

{

fishMov.fish.fish_gr.gotoAndStop (2);

= missle3.x missle3.y = - 100;

missle3.alpha = 0;

ay += 5;

vx = vy = 10;

}

if (missle4.missleCircle.hitTestObject (fishMov.fish))

{

fishMov.fish.fish_gr.gotoAndStop (2);

= missle4.x missle4.y = - 100;

missle4.alpha = 0;

ay += 5;

vx = vy = 10;

}

if (missle1.missleCircle.hitTestObject (fishMov1.fish))

{

fishMov1.fish.fish_gr.gotoAndStop (2);

= missle1.x missle1.y = - 100;

missle1.alpha = 0;

ay1 += 5;

vx1 = vy1 = 10;

}

if (missle2.missleCircle.hitTestObject (fishMov1.fish))

{

fishMov1.fish.fish_gr.gotoAndStop (2);

= missle2.x missle2.y = - 100;

missle2.alpha = 0;

ay1 += 5;

vx1 = vy1 = 10;

}

if (missle3.missleCircle.hitTestObject (fishMov1.fish))

{

fishMov1.fish.fish_gr.gotoAndStop (2);

= missle3.x missle3.y = - 100;

missle3.alpha = 0;

ay1 += 5 ;

vx1 = vy1 = 10;

}

if (missle4.missleCircle.hitTestObject (fishMov1.fish))

{

fishMov1.fish.fish_gr.gotoAndStop (2);

= missle4.x missle4.y = - 100;

missle4.alpha = 0;

ay1 += 5;

vx1 = vy1 = 10;

}

if (missle1.missleCircle.hitTestObject (fishMov2.fish))

{

fishMov2.fish.fish_gr.gotoAndStop (2);

= missle1.x missle1.y = - 100;

missle1.alpha = 0;

ay2 += 5;

vx2 = vy2 = 10;

}

if (missle2.missleCircle.hitTestObject (fishMov2.fish))

{

fishMov2.fish.fish_gr.gotoAndStop (2);

= missle2.x missle2.y = - 100;

missle2.alpha = 0;

ay2 += 5;

vx2 = vy2 = 10;

}

if (missle3.missleCircle.hitTestObject (fishMov2.fish))

{

fishMov2.fish.fish_gr.gotoAndStop (2);

= missle3.x missle3.y = - 100;

missle3.alpha = 0;

ay2 += 5;

vx2 = vy2 = 10;

}

if (missle4.missleCircle.hitTestObject (fishMov2.fish))

{

fishMov2.fish.fish_gr.gotoAndStop (2);

= missle4.x missle4.y = - 100;

missle4.alpha = 0;

ay2 += 5;

vx2 = vy2 = 10;

}

if (fishMov.fish.hitTestObject (player))

{

playeray += 2.2;

player.gotoAndStop (2);

}

if (fishMov1.fish.hitTestObject (player))

{

playeray += 2.2;

player.gotoAndStop (2);

}

if (fishMov2.fish.hitTestObject (player))

{

playeray += 2.2;

player.gotoAndStop (2);

}

}

stage.addEventListener (KeyboardEvent.KEY_DOWN, onKeyPressed);

int onKeyPressed(evt:KeyboardEvent):void

{

switch (evt.keyCode)

{

Case Keyboard.LEFT:

playervx-= 1;

break;

Case Keyboard.RIGHT:

playervx += 1;

break;

Case Keyboard.UP:

playervy-= 0.7;

break;

Case Keyboard.DOWN:

playervy += 0.7;

break;

Case Keyboard.A:

player.rotation-= 26;

Case Keyboard.D:

+= player.rotation 13

Case Keyboard.SPACE:

missleLaunch();

missleCounter += 1;

trace (missleCounter);

break;

by default:

trace ("code:", evt.keyCode);

}

}

}

}

}

You exaggerated once again, simply to show the relevant code at the launch of a missile, which is what calls the missleLaunch() function.  You'll get the hang of limiting what to show later.

The launch is initiated in the switch code in the onKeyPressed() function.  If you look at the switch case code for your controls for rotation, you will find something missing in these two cases which is not absent in other cases.

Tags: Adobe Animate

Similar Questions

  • How to stop disk check to run every time that windows vista starts?

    How to stop disk check to run every time that windows vista starts? I had a problem with one of my backup disks so I removed it, but now the drive is still running a disk check whenever I boot my system. It takes so long to run and there is no error, but it starts every time. Why and how can I make sure that she? I read similar questions, but they don't tell you how to run a disk check, they mention however that "If you want to cancel the regular disk for some reason check, check out this guide." but tell you what guide or link?

    Hello

    This tells you how to enable and disable it:

    How to difficulty Chkdsk will not run at startup in Vista
    http://www.Vistax64.com/tutorials/130824-CHKDSK-will-not-run-startup-Vista.html

    Video: Stop Check Disk from constantly running at startup in Windows Vista
    http://blogs.TechRepublic.com.com/itdojo/?p=193

    ChkDsk runs every time Windows starts.
    http://www.WinVistaClub.com/T20.html

    I hope this helps.
    Rob - bicycle - Mark Twain said it is good.

  • How to stop a URL's InternetExplorer every time?

    For some pages, I said once to open in Internet Explorer, but now I want to stop this feature for some of these pages. How?

    I found myself the answer: under 'options', there is a button 'manage addons '.
    Then under' options of IE View ", I can change the URL list that is sent to IE to this addon."
    Problem solved.

  • How can I get my printer to stop printing a test page every time I turn it on?

    everytime I turn on my printer a page is printed. I would like to stop this.

    Hi TerriValenzuela,

    ·         What is the brand and model of the printer?

    ·         Did you the latest changes on the computer?

    I suggest you try the steps mentioned below and check if it helps.

    1. click on start, devices and printers.

    2. right click on your printer, select properties and all of the tabs look for a radio button titled "test page printed on startup."

    3. uncheck this option.

  • How to eliminate the upcoming welcome screen every time pc turned on?

    Hello once again;  It is not the screen projection I "M trying to eliminate, but logon screen it's self.   HP pavition HP - 1148p;    Windows 7 Home Edition premium you think for your time

    Hello

    Please keep your question on the same post otherwise very hard to follow. Please use the folliwng steps:

    http://pcsupport.about.com/od/Windows7/HT/auto-logon-Windows-7.htm

    Kind regards.

  • I've updated for picture with the captain and when I plug in my iPhone it loads the same pictures twice each time how it stop loading the same things every day?

    I've updated for picture with the captain and when I plug in my iPhone it loads the same pictures twice each time how it stop loading the same things every day?  I tried to make the old default iphoto but picture still open when I plug in my iPhone?

    I tried to make the old default iphoto but picture still open when I plug in my iPhone?

    When the iPhone is connected and Photos opens, select iPhone in sideba of the windowr of Photos. Then, uncheck the option 'Open for this iPhone Photos' below the toolbar.  Do this for all your iPhones. The hook should be unmarked for each device individually.

  • HP DesignJet 1000 series, a bad cable rear transport stop in the same place every time?

    Hello. On a series of 1000 HP DesignJet 1050c more think that FW A.52.02, a bad cable rear transport stop in the same place every time?  It stops just to the right of each start, attached photo Center.  Do not know if it is directed to the left or right at the time; I asked the customer, but it has not yet responded.  It is hundreds of miles away with customer.  I was not there; I try to get a very good idea of what everything I need and that you need to do before I travel such a distance.

    It gets the error "check printhead path type (2).  Customer said that began as he tried to pass to 24 "paper roll of I think 36" roll of paper.  Maybe this is related to the different movements to transport would be to manage different width, but there will be an underlying problem.  (Well, I guess it does now any width.)  I read that if transport stops in the same place every time when you start, it's probably one of the following:

    1 necessary transport height adjustment.

    2 tubes of rub excessively in the channel of tubes.

    3. bad transport (Mouasher Sa'ad says that the bad capacitors once a trolley stop at the same place;) Guess it could be a bad encoder sensor but think the transport would simply jump a quarter inch or so if the case.)

    Well, guess it might be something to the top with the belt too, so:

    4. bad belt (once I had 1 too short and kept cause type 2 error - stop inches couple out right every time)

    I cleaned and lubricated all - channel rods and tubes of cursor. It worked fine for 5 months.

    Here, I simply want to exclude ideally that a bad end cable would cause traffic to stop at the same place every time.

    Thanks for any input.

    Paul

    Usually, a bad end cable will not cause you have. It could be one of the items you listed, but could also be the encoder being dirty in this place. Most of the time it's the belt as a defect in a bad belt could stop at the same place. If the sheath is a problem most of the time it stops at the opening of the left side. Also, if the tubes most of the time you can fix a bunch of heavy clear packing on the rim tape, tubes rub against and which solves the problem.

  • How can I disable the onion? every time I start Internet onion appears, what should I do to turn it off?

    How can I disable the onion? every time I start Internet onion appears, what should I do to turn it off?

    ·       Click Start on your desktop
    ·       Type msconfig in the search box and press ENTER.
    If you are prompted for an administrator password or a confirmation, type the password, or click on continue.
    Go to the Startup tab, locate Internet onion and uncheck the box to open at startup.

    I could also go into Panel, programs and features and see if you can uninstall Internet onion.

    Thank you

  • resolution problem with my monitor every time I turn on

    I have a monitor to display wide w1907 h p on nvidia gforce7050/nvidia nforce 6101.2 weeks I had restore the desktop pc top of page back to default settings since then every time I turn on the screen starts to the resolution of the game and then after a few seconds, it turns into the resolution.i minimum re on this return to the recommended resolution and it stops on this setting until I have put it off and then when I use the PC again I have to repeat the process thanks t..

    Hi Tony,.

    Have you checked that you have the correct nvidia gforce drivers installed from the manufacturers Web site?
    This problem may appear when you have a general driver for the graphics card.

    You could try reinstalling the drivers for the graphics card because it could have been corrupted somehow when return you to the default settings.

    Kind regards

    Joel

  • Form diagnosis of prints every time I turn on the printer.

    I recently put in a new cartridge black ink (HP product) and every time I turn on my printer prints a diagnostic sheet - this is the first time that this has happened and I used the printer for about 4 years. Thanks for any help.

    OK, the Photosmart C3180 see the troubleshooting here page.

  • I have a new Omni. Can I put it, so I did not type my password every time I turn it on?

    I have a new Omni.  Can I put it, so I did not type my password every time I turn it on?

    If there is an option to check that I missed.

    If you go to user accounts, you can change the password. Create no password in the new password just press ENTER to block.

  • How to stop an application to change the time system?

    Hello

    I have an application that is affecting my time GMT system, but not the time zone.

    How to stop applications to change the time system.
    I run gpedit.msc and changed the policy of "change the time system" in person, and the request is received to change the system time.

    Help.

    Concerning
    TANIEL

    "TanielB" wrote in the new message: * e-mail address is removed from the privacy... *

    Hello

    I have an application that is affecting my time GMT system, but not the time zone.

    How to stop applications to change the time system.
    I run gpedit.msc and changed the policy of "change the time system" in person, and the request is received to change the system time.

    Help.

    Concerning
    TANIEL

    Are you sure that it is an application that is causing the problem?

    When you are connected to the Internet, Win XP will periodically synchronize with a time server.  If you have Win XP on the wrong time zone, your computer displays the local time 'bad '.

    Double click on the time (lower RH of your screen) and select the time zone tab.  Select the correct time zone for your location and check the DST box.  If necessary, change the time manually to your local time and save your changes.

    Then select the time tab Internet - and make sure that you have a server in the server field.  I use the time - a.nist.gov.  There are many alternative servers, including time.nist.gov and time.windows.com.  Click 'Update now'.

  • my browser opens with the page of the previous session, not my home page. Why? How can I reset to open up every time my homepage?

    I want my home page to open to my home page every time I open my browser. I think the browser's save my previous session tabs, but I'm not sure. I really started having aggravated with this browser and I love firefox... Please help me solve this problem.

    BTW, I tried to go to "tools/options...". "but I don't know where are my 'tools '. When I click on the button at the top left of my browser firefox it does not give me a "Tools" tab, and options just talking about toolbars and others. I don't understand.

    To access the Tools menu:

    Firefox, as well as a number of Windows programs, will show the menus (file, editing, display etc.) bar when you press the ALT key. You can then choose "Options" in the Tools menu.
    Otherwise, click 'Options' in the menu Firefox Button.

    (If you do not want to keep the bar menus around without pressing Alt, click the arrow next to 'Options' and choose 'Menu Bar'. The Firefox button will be replaced by the menu bar).

    Set your home page:

    Open the Options Panel and select the "Général" tab if it is not already. You can change what happening "When Firefox starts" there.

  • How can I increment/decrement a value every time you press a button on the controller

    I'm in train to find a way to increment or decrement a value every time you press a button on the controller (Boolean).

    The function in the tutorial, I found is the value go up by huge amountswhile, the button is pressed, what I need is a way to have the value go up by units whenever you press the x key.

    I would use a timer, but sometimes, the button can be pressed quickly, or may be required.

    in standard programming, I would have the system to wait for the button to press, and then increment a and wait until the button is released before moving on. For the moment, I still have not found a way to do this.

    -Zeno

    Just we a registry change and compare the old and new of the Boolean values.

    More simple would be the 'includes the function. If you connect as shown in this recent example, you get a trigger when the Boolean goes off-> on between two iterations.

  • XP installation update every time I turn the computer off.

    I don't know what happens, whenever I turned off my PC (running Windows XP Home Edition, Version 2002, SP3) for the last week or so, it is said that it will install an update, if I disable normally.  I mean, click the button, it installs and turns off, and then the next time that I turn it off, it happens again.  1 update every time, I let it run all along, just as I always before.

    Teepet,

    Please download and save the Fixit on this page - How to reset the Windows Update components?
    Once the download is complete, close all open programs and browsers.
    Now run MicrosoftFixit50202.msi and choose it's default mode.

    When the Fixit has finished, open automatic updates in Control Panel. Do not restart the system, but even if you have been invited to.
    Set the update option for " download updates for me, but let me choose when to install them ." Click on apply, then OK.
    Close the automatic updates.
    Reboot the system now.

    Doing the above will force the automatic updates to download all the updates that are missing.
    When the Update icon, click it.
    Please note that updates are available and their numbers of KB.
    Close the window.
    For now, do installation No updates until what you have posted to those to whom they are.

    Expert MowGreen Windows IT Pro - consumer safety

Maybe you are looking for