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

incredibly low floating point precision #94

Open
galoko opened this issue May 18, 2018 · 0 comments
Open

incredibly low floating point precision #94

galoko opened this issue May 18, 2018 · 0 comments

Comments

@galoko
Copy link

galoko commented May 18, 2018

If I change linear velocity by amount less than or equal to absolute value of 10e-2 then step will make body advance it's position according to it's speed but after the step body's linear velocity will be equal to zero. Maybe this is intended behavior, but it seems rather strange, so... is it? Is there something I can do about it
at all?

edit:
my guess: it has something to do with b2_linearSleepTolerance, but the thing is, Box2D C++ works just fine with any values, even as low as 10e-5

Here's the code for demonstration:

        for (let body = world.GetBodyList(); B2D.getPointer(body) !== 0; body = body.GetNext()) {

            if (body.GetType() === B2D.b2_dynamicBody) {

                let velocity = body.GetLinearVelocity();

                // -0.011 works by the way
                let velocityDelta = -0.01;
                velocity.Set(velocity.get_x(), velocity.get_y() + velocityDelta);

                body.SetLinearVelocity(velocity);

                velocity = body.GetLinearVelocity();

                // output is: velocity before step: -0.009999999776482582
                console.log("velocity before step: " + velocity.get_y());
            }
        }

        // arguments here doesn't matter
        world.Step(1, 20, 10);

        for (let body = world.GetBodyList(); B2D.getPointer(body) !== 0; body = body.GetNext()) {

            if (body.GetType() === B2D.b2_dynamicBody) {

                let velocity = body.GetLinearVelocity();

                // output is: velocity after step: 0
                console.log("velocity after step: " + velocity.get_y());
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant