Linear acceleration

Discuss issues specific the Java port of Box2D
box
Posts: 2
Joined: Thu Jan 11, 2018 7:28 am

Linear acceleration

Postby box » Thu Jan 11, 2018 7:42 am

Each iteration I call method "body.applyForce(new Vec2(10, 0), new Vec(0, 0));"

I expect that after each iteration body linear speed will be increased to appropriate value, and position will be look like
step 1: speed is (0, 0), position is (0, 0)
step 2: speed is (1, 0), position is (1, 0)
step 3: speed is (2, 0), position is (3, 0)
step 4: speed is (3, 0), position is (6, 0)
step 5: speed is (4, 0), position is (10, 0)

But instead of it, I got this output:
step 1: speed is (0, 0), position is (0, 0)
step 2: speed is (1, 0), position is (1, 0)
step 3: speed is (1, 0), position is (2, 0)
step 4: speed is (1, 0), position is (3, 0)
step 5: speed is (1, 0), position is (4, 0)

Why it happen, and how I can solve my problem?
ps also, I set world.setAutoClearForces(false); but nothing was changed.

box
Posts: 2
Joined: Thu Jan 11, 2018 7:28 am

Re: Linear acceleration

Postby box » Thu Jan 11, 2018 1:10 pm

Hm, I found this code inside or "Island" class:

Code: Select all

if (translationx * translationx + translationy * translationy > Settings.maxTranslationSquared) {
        double ratio = Settings.maxTranslation
            / MathUtils.sqrt(translationx * translationx + translationy * translationy);
        v.x *= ratio;
        v.y *= ratio;
      }

This part make my body move slowly than I need. Anybody know, why it was used for?


Return to “Java”



Who is online

Users browsing this forum: Google [Bot] and 2 guests