double vx = state.get($vx);
double vy = state.get($vy);
double ax = state.get($ax);
double ay = state.get($ay);
final AABB bounds = global.bounds;
final double duration = (double) (now - lastMoved) / TimeUnit.SECONDS.toMillis(1);
final double duration2 = duration * duration;// * Math.signum(duration);
x = x + (vx + exVx) * duration + ax * duration2 / 2.0;
y = y + (vy + exVy) * duration + ay * duration2 / 2.0;
vx = vx + ax * duration;
vy = vy + ay * duration;
// before limitSpeed
state.set($vx, vx);
state.set($vy, vy);
limitSpeed();
vx = state.get($vx);
vy = state.get($vy);
assert !Double.isNaN(vx + vy);
if (x > bounds.max(X) || x < bounds.min(X)) {
x = min(x, bounds.max(X));
x = max(x, bounds.min(X));
vx = -vx * SPEED_BOUNCE_DAMPING;
ax = 0;
}
if (y > bounds.max(Y) || y < bounds.min(Y)) {
y = min(y, bounds.max(Y));
y = max(y, bounds.min(Y));
vy = -vy * SPEED_BOUNCE_DAMPING;
ay = 0;
}
assert !Double.isNaN(x + y);