Why is the head jumping around the body?

I wrote the following code for Head which should follow the body like a spring. I added friction so the head will stop bouncing sometime but no success. The head keeps jumping near the beggining of the spring (which is the beggining of the body) and not stopping. What should I do to make the head stop at some time?
  final static int MASS = 10;
  final static int FRICTION = 100;
  private final double hardness = 3;
public void followBody(Body body) {
double[] coards = getCoardinatesBy(getRadius(), body.getXCoardStart(), body.getYCoardStart(), 180+body.getAngel()); // get the coordinates of the beginning of the spring (where should the head be in the end
        coards[0] -= getRadius();
        coards[1] -= getRadius();
        if (getYSpeed() < 0) {
            this.setYAcceleration((getYForce(coards[1]) + FRICTION)/MASS);
        } else if (getYSpeed() > 0) {
            this.setYAcceleration((getYForce(coards[1]) - FRICTION)/MASS);
        } else if (Math.abs(getYForce(coards[1])) < FRICTION ) { //static friction, equal to the power or less
            this.setYAcceleration(0);
        } else {
            this.setYAcceleration(getYForce(coards[1]) / MASS); // speed is zero. new the head is far away from the spring
        if (getXSpeed() < 0) {
            this.setXAcceleration((getXForce(coards[0]) + FRICTION)/MASS);
        } else if (getXSpeed() > 0) {
            this.setXAcceleration((getXForce(coards[0]) - FRICTION)/MASS);
        } else if (Math.abs(getXForce(coards[0])) < FRICTION) { // static friction, equal to the power or less
            this.setXAcceleration(0);
        } else {
            this.setXAcceleration(getXForce(coards[0]) / MASS); // speed is zero. new the head is far away from the spring
   double getYForce(double y){
        return hardness*(y-yCoardStart);
    double getXForce(double x){
        return hardness*(x-xCoardStart);
static double[] getCoardinatesBy(double height, double startX, double startY, double angel) {
        double[] coardinates = new double[2];
        coardinates[1] = startY - (height * Math.sin((Math.toRadians(angel))));
        coardinates[0] = startX + (height * Math.cos(Math.toRadians(angel)));
        return coardinates;
  public void update() {
        xSpeed += xAcc;
        ySpeed += yAcc;
        xCoardStart += xSpeed;
        xCoardEnd += xSpeed;
        yCoardEnd += ySpeed;
        yCoardStart += ySpeed;
        angularVelocity+=angularAcc;
        this.angel += angularVelocity;
        autoSetEndXY();
private void autoSetEndXY() {
        double[] coards = getCoardinatesBy(height, xCoardStart, yCoardStart, angel);
        yCoardEnd = coards[1];
        xCoardEnd = coards[0];
    }Edited by: Vitali.pom on May 20, 2012 6:01 AM
Edited by: Vitali.pom on May 29, 2012 12:19 AM
Edited by: Vitali.pom on Jun 26, 2012 12:05 PM

Thanks for the try. That's what I tried:
public void followBodyPart(BodyPart body) {
        double[] coards = getCoardinatesBy(getRadius(), body.getXCoardStart(), body.getYCoardStart(), 180+body.getAngel());
        coards[0] -= getRadius();
        coards[1] -= getRadius();
       if (getYSpeed() < 0) {
            this.setYAcceleration((getYForce(coards[1]) + FRICTION)/MASS);
        } else if (getYSpeed() > 0) {
            this.setYAcceleration((getYForce(coards[1]) - FRICTION)/MASS);
            System.out.println("Player moved.");
        } else if (Math.abs(getYForce(coards[1])) < FRICTION) {
            this.setYAcceleration(0);
            System.out.println("y force is 0.");
        } else {
            this.setYAcceleration((getYForce(coards[1]))/ MASS);
        if (getXSpeed() < 0) {
            this.setXAcceleration((getXForce(coards[0]) + FRICTION)/MASS);
        } else if (getXSpeed() > 0) {
            this.setXAcceleration((getXForce(coards[0]) - FRICTION)/MASS);
            System.out.println("Player moved.");
        } else if (Math.abs(getXForce(coards[0])) < FRICTION) {
            this.setXAcceleration(0);
            System.out.println("x force is 0.");
        } else {
            this.setXAcceleration((getXForce(coards[0]))/ MASS);
    }And that's what I got (repeating in the end):
Player moved.
y force is 0.
y force is 0.
Player moved.
y force is 0.
y force is 0.
Player moved.
y force is 0.
Player moved.
Player moved.
Player moved.
Player moved.
Player moved.
Edited by: Vitali.pom on Jun 16, 2012 3:54 AM

Similar Messages

  • Why is the body area of my site a different size in the preview view than than in the design view?

    Why is the body area of my site a different size in the preview view than than in the design view?

    Why is the body area of my site a different size in the preview view than than in the design view?

  • Why is the body of text a picture

    Hello
    Why is the body of text a picture after converting PDF to DOC?

    Hi CrazyFred,
    Have you tried triple-clicking in the Word document to select text? If that doesn't work, we'll want to take a closer look at how the original PDF was created, as that can have an affect on how well the PDF converts. Please see Will Adobe ExportPDF convert both text and form... | Adobe Community. If the PDF was created by a third-party PDF producer, it may not be well-written, and that can lead to conversion issues.
    You can tell how the PDF was created by choosing File > Properties when the PDF is open in Reader. The PDF Producer is listed on the Description tab.
    Best,
    Sara

  • Why is the body/content of all my emails invisible except for a few lines in the small preview pane?

    The body/content of my emails is invisible in the large/main part of the screen when using the mail app on my iPad.  I can see some of the text from each email in the small preview pane on the left side of the screen (when holding iPad in landscape orientation).  The only way I can read the content of an email is to forward or reply and then the body/content appears.  How do I fix this problem??

    Try turning the account off and on : Settings > Mail, Contacts, Calendars , then tap the account on the right, slide Mail to 'off', exit settings and go back into the Mail app, and then go back to Settings and slide Mail back to 'on'
    If that doesn't work then try closing the Mail app completely : from the home screen (i.e.not with the Mail app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Mail app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    Also do a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Why does the body of the email vanish??

    I have the most annoying issue with mail that is beginning to wind up my clients!
    About one in five of the emails I send appear in the other person's inbox with no text in the body of the email – instead, the text is attached in a file (the name of which is something along the lines of ATT1234567.txt). I've narrowed it down, and it seems to be when I've formatted the text (bolds, lists etc) and I think it's when I combine this with attaching another file, commonly a draft PDF I'm sending for approval.
    Colleagues know now to check for an attachment and read my comments, but clients just think I'm rude, when they get a PDF sent with no text from me! Any help would be sooooooooo appreciated.

    Are you using RTF for message composition or Plain Text?
    If RTF, try using Plain Text instead when sending messages thru an Exchange Server. Windows Outlook does the same when using RTF for message composition but sending messages thru an Exchange Server also has an effect.
    http://www.webopedia.com/TERM/T/TNEF.html
    http://www.dwheeler.com/essays/microsoft-outlook-tnef.html

  • Why dont the body of my emails appear?

    I'm viewing emails and the body of the email is not appearing.  Only when I Reply, do i see the body.   I am travelling abroad and the connection is slow.   Could that be the issue?  Or is there some setting that is preventing the body of the email from appearing.

    Try a Reset [Hold the Home and Sleep/Wake buttons down together for 10 seconds or so (until the Apple logo appears) and then release. The screen will go blank and then power ON again in the normal way.] It is app and data safe!

  • HT203171 Why is my cursor jumping around?

    THe cursor on my Macbook Pro has suddenly started jumping around even when I am touching nothing. It seems to have started after I installed a free Photoshop trial. I have done a Safe Start but nothing  has changed.

    There are several possible causes for this issue. Please take each of the following steps that you haven't already tried until it's resolved. Some may not apply in your case.
    1. Follow the instructions in this support article, and also this one, if applicable. A damaged or defective AC adapter could be the cause, even if it's the right kind.
    2. Press down all four corners of the trackpad at once and release. If there's any effect, it's likely to be temporary, and in that case the unit must be serviced or replaced.
    3. Open the Bluetooth preference pane in System Preferences and delete all pointing devices other than the trackpad, if applicable. Disconnect any USB pointing devices. By a "pointing device," I mean a peripheral that moves the cursor, such as a trackpad, mouse, trackball, or graphics tablet. A plain keyboard is not a pointing device.
    4. Start up in safe mode and test, preferably without launching any third-party applications. If you don't have the problem in safe mode, but it comes back when you restart as usual, stop here and post your results. Do the same if you can't start in safe mode. If there was no difference in safe mode, go on to the next step.
    5. Reset the System Management Controller.
    6. If you're using a Bluetooth trackpad or mouse, investigate potential sources of interference, including USB 3 devices.
    7. A swollen battery in a portable computer can impinge on the trackpad from below and cause erratic behavior. If you have trouble clicking the trackpad, this is likely the reason. The battery must be replaced without delay.
    8. There's a report that a (possibly defective) Thunderbolt Ethernet adapter can cause the built-in trackpad of a MacBook to behave erratically. If you're using such an adapter, disconnect it and test.
    9. There's also a report of erratic cursor movements caused by an external display that was connected but not turned on.
    10. If none of the above applies, or if you have another reason to think that your computer is being remotely controlled, remove it from the network by turning off Wi-Fi (or your Wi-Fi access point), disconnecting from a Bluetooth network link, and unplugging the Ethernet cable or USB modem, whichever is applicable. If the cursor movements stop at once, you should suspect an intrusion.
    11. Make a "Genius" appointment at an Apple Store to have the machine and/or external trackpad tested.

  • Why is my cursor jumping around all over the place.

    Typing on my Macbook Pro has become nearly impossible.  As I'm typing along I'll look up and the cursor has jumped to someplace else on the page...either inputting new text where it doesn't belong or typing over something else.  In fact it happened twice just while typing this short question?  I googled it and saw one fix posted in 2010...but nothing in OS X Yosemite seems to match what they suggested as a fix.  It regards ignoring random trackpad input.  Can anyone here help me?

    There are several possible causes for this issue. Please take each of the following steps that you haven't already tried until it's resolved. Some may not apply in your case.
    1. Follow the instructions in this support article, and also this one, if applicable. A damaged or defective AC adapter could be the cause, even if it's the right kind.
    2. Press down all four corners of the trackpad at once and release. If there's any effect, it's likely to be temporary, and in that case the unit must be serviced or replaced.
    3. Open the Bluetooth preference pane in System Preferences and delete all pointing devices other than the trackpad, if applicable. Disconnect any USB pointing devices. By a "pointing device," I mean a peripheral that moves the cursor, such as a trackpad, mouse, trackball, or graphics tablet. A plain keyboard is not a pointing device.
    4. Start up in safe mode and test, preferably without launching any third-party applications. If you don't have the problem in safe mode, but it comes back when you restart as usual, stop here and post your results. Do the same if you can't start in safe mode. If there was no difference in safe mode, go on to the next step.
    5. Reset the System Management Controller.
    6. If you're using a Bluetooth trackpad or mouse, investigate potential sources of interference, including USB 3 devices.
    7. A swollen battery in a portable computer can impinge on the trackpad from below and cause erratic behavior. If you have trouble clicking the trackpad, this is likely the reason. The battery must be replaced without delay.
    8. A defective peripheral device or a damaged cable can cause the built-in trackpad of a MacBook to behave erratically. If you're using any wired peripherals, disconnect them one at a time and test.
    9. There's also a report of erratic cursor movements caused by an external display that was connected but not turned on.
    10. If none of the above applies, or if you have another reason to think that your computer is being remotely controlled, remove it from the network by turning off Wi-Fi (or your Wi-Fi access point), disconnecting from a Bluetooth network link, and unplugging the Ethernet cable or USB modem, whichever is applicable. If the cursor movements stop at once, you should suspect an intrusion.
    11. Make a "Genius" appointment at an Apple Store to have the machine and/or external trackpad tested.

  • Why is the Body-copy of my outgoing emails duplicated?

    People have been telling me that when they receive an e-mail from me, the contents are duplicated. Immediately below my message is a duplicate of the message, signature etc. It's odd, and irritating because it does not look very professional. Anyone got any ideas as to why this is happening?

    Try turning the account off and on : Settings > Mail, Contacts, Calendars , then tap the account on the right, slide Mail to 'off', exit settings and go back into the Mail app, and then go back to Settings and slide Mail back to 'on'
    If that doesn't work then try closing the Mail app completely : from the home screen (i.e.not with the Mail app 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Mail app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    Also do a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • Why is my iPad jumping around like it has a virus?

    My iPad has gone insane.  The cursor won't stay put.  When i click on an app or folder other apps or folders open, it is acting the way a PC would if it had a virus.  n I am very concerned.  I only got this message out because I used an external keyboard!!  Help!  Has anyone else experienced this? 
    And let me answer now, I did not jail break my iPad and it does have the most recent ios 7.1 update. 

    Since it's not jailbroken, it's not malware of any kind. There's no known malware capable of infecting an iPad that hasn't been jailbroken.
    In addition, it is a common internet myth that such behavior is the result of a virus. In reality, no hacker wants to go waving the cursor around under the user's nose. (Or, in the case of an iOS device, tapping and navigating, since there is no cursor.) This is almost never the result of malware on a computer, and definitely never in the case of an iPad.
    First, try resetting your device. Press and hold both the home button and the sleep/wake button for about 10 seconds, until the screen turns off. Ignore the slider that will appear. Release the buttons, then press and hold the sleep/wake button until the Apple logo appears. This is the equivalent of a reboot, and should not affect your data or apps.
    If that doesn't help, try restoring your device from backups, and if that doesn't help, restore it to factory settings (ie, do not restore a backup). See:
    http://support.apple.com/kb/ht1414
    If none of that helps, the issue is caused by some kind of hardware problem, and the device will need to be repaired or (more likely) replaced.

  • Why is my mouse jumping around?

    My mouse keeps moving randomly all over the screen but I don't even touching my macbook

    Jumpy Trackpad
    http://support.apple.com/kb/TS1449
    Go step by step and test.
    1. Restart
    2. Shut down the computer.
        Clean the trackpad with moist not wet microfiber cloth.
        System Preferences > Point & Click
        Try turning off three finger dragging and then turning it on after  testing.
    3. Is there any Bluetooth device nearby with failing batteries? If so, replace the batteries.
      4. Reset PRAM:   http://support.apple.com/kb/PH14222
    5. Reset SMC.     http://support.apple.com/kb/HT3964
        Choose the method for:
        "Resetting SMC on portables with a battery you should not remove on your own".
    6. Close all windows and quit all applications.
        Click the spotlight -the magnifying glass icon- in the menu bar. Enter Disk utility in the box.
        Select Disk Utility from the drop down. When the Disk utility window opens up,
        select  Macintosh HD, then First Aid.
        Click Repair Disk Permissions button.
        Ignore the  time remaining estimate.
        Last 1 minute may take longer.
      If this does not solve the problem, you may have to take the computer to the Apple store
    to have it checked out.
    Best.

  • Why does the screen on my iPad mini jump around?  Apps open and close, I can't get back to the home screen.  Is my mini possessed?

    Why does the screen on my iPad mini start jumping--larger, smaller--can't close apps.  I reboot and still it happens.  Any suggestions?

    If the unit has NEVER been jailbroke, first try a system reset.  It cures many ills and it's quick, easy and harmless...  Hold down the on/off switch and the Home button simultaneously until you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  It could take well over an hour!  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow the on-screen directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.  You WILL lose all of your data (game scores, etc,) but, for the most part, you can redownload apps and music without being charged again.  Also, if you have IOS-7, read this.

  • Why does my selection on the touch screen jump around?

    Throughout the day my phone starts selecting the wrong item on my iphone; if I select contacts it brings up something else like email, if I select back it tries to delete, try to scroll up or down and it jumps around. I've restored my phone twice, restarted, updated it, made sure it's fully charged, and while there are times it works fine, it inevitably goes back to this problem. Sometimes if I lay it flat or turn it to landscape it will work ok, but more often than not, it doesn't.
    I'm past my warranty and want to find a fix without buying a new phone. I need help!!!!

    Sync everything to the computer.
    Restore as new.  Test.
    If problem persists, call Apple and arrange a repair.  I doubt if you'll need to.  It is most likely a software issue and the restore should fix it.  If it does turn out to be hardware, an out of warranty repair would be $199.  Not cheap, but cheaper than buying a new phone before being elligible to upgrade.

  • When you are loading a CD in iTunes why does the artist scrolling jump around

    With every version of itunes: While I am adding a CD into my iTunes Library, I like to scroll through the artists names and sometimes cleaning up my library. But everytime I am adding in a CD the arists names jump around. Basically if i am scrolling down the alpha order of artists in the left artists pane, unless I act really fast it jumps back to A at the very beginning. If if I am able to clik and highlight a particular name, sometimes it wont say and again jumps back to the top. All is well when I am not loading in music. This happens always and it seems that itunes cannot do multi things at once.
    Anyone have a solutiuon or is it just a part of the application.

    I don't believe that the album artwork will be retrieved. Songs purchased form the iTunes music store sometimes arrive with the album artwork if its available... but this is special a feature of the iTunes Music Store.
    You can manually add album artwork to your library.
    Just go into the online Help within iTunes, and search for 'art'.
    You'll be shown detailed instructions on how to add your own artwork.

  • Trackpad draging and jumping around the screen

    trackpad works for a while but then the trackpad begins to drag (when I move my finger around the trackpad, the curser either doesent move at all or moves very slowly) and the curser begins to jump around the screen when the trackpad and computer isent being touched. I tried to connect a wireless mouse and it too bagan with the same problems. if anyone has any ideas of how to fix it, im all ears.

    Yes i've gotten this twice.
    Once from not quite legitmate software.
    Once from a sketch NSFK site.
    Both times, it was easily resolved for me by shutting down.
    Follow the procedure to reset SMC controller ( make sure you do this properly ) Guides are available on Apple's support page.
    Immediatly after the SMC reset before any other reboot reset the PRAM several times.
    then reboot as normal.
    ...I'm not sure what exactly is going on.. I think some setting is getting adjusted and set EFI that's why normal reboots, safe mode, nothing else solves it.   One of the more eye opening aspect of it for me was when I rebooted my macbook into Windows7 via bootcamp and it still presisted.   At that point it had NOTHING to do w/ OS software, plist, safe mode or myraid of other suggestions you'll encounter. 

Maybe you are looking for