Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix air friction calculation #669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Commits on Sep 24, 2018

  1. fix air friction calculation

    The code is slghtliy confusing because `velocityPrevX` and
    `velocityPrevY` actually define a distance. The real velocity can be
    calculated as `velocityPrevX / deltaTimePrev` and `velocityPrev /
    deltaTimePrev` where `deltaTimePrev = deltaTimeScaled / correction`.
    
    This is the formular without air friction:
    
    ```
    velocity.x = velocityPrevX * correction + body.force.x / body.mass * deltaTimeSquared
    ```
    
    Air friction is a force that acts in the opposite direction of the
    velocity. It is proportional to velocity (for small velocity):
    
    ```
    velocity.x = velocityPrevX * correction + (body.force.x - (body.frictionAir * velocityPrevX / deltaTimeScaled * correction)) / body.mass * deltaTimeSquared
    ```
    
    which can be converted to:
    
    ```
    velocity.x = velocityPrevX * (1 - body.frictionAir * deltaTimeScaled / body.mass) * correction + body.force.x / body.mass * deltaTimeSquared
    ```
    xi committed Sep 24, 2018
    Configuration menu
    Copy the full SHA
    3a4361e View commit details
    Browse the repository at this point in the history