2
votes

gravity: (x=0, y=EARTH)

I want make permanent bouncing ball. For example I set it coords (200, 200), after it falls down to ground, bounces and return to the same coords as in begin (200, 200). I tried to play with density, elasticity, friction and I got some similar behavior, but is changing. I google a lot and found that the problem is because of rounding floats. Question: which value is changing in engine and which I need to reset after that value will become more then some delta?

Second question: why if I set fixtures like this: fixtures(density=1, elasticity=1, friction=0) it not bounced to the same height, but bouncing with every bounce higher? I set elasticity something like 0,981f

Third question: how one object fixtures depends on second object fixtures? example: ball(1f, 0.6f, 1f) wall(1f, 0.6f, 0f)

and

ball(1f, 0.6f, 1f) wall(1f, 0.6f, 0.5f)

what will change?

1
Do you really need precisely the same coordinates every time or just roughly constant kinetic + potential energy of the ball? - JohnEye
I need that ball return to the same height (+/- 15 px can be fault) look here: Example - Aleksandrs
If I were you, I would give the body elasticity larger than 1 and monitor its velocity. If the body's velocity gets too large, the monitor would slow it down. This would keep the system in balance - the body would keep gaining a bit of energy and the excess would be trimmed off. - JohnEye
I see. Perhaps you could measure the velocity just before the ball touches the ground for the first time and then set it as maximum velocity instead of the hardcoded value. Or create a table of values for different heights and figure out an appropriate function that would give you the right value for every height. Depending on the game mechanism, lateral velocity may come into play though. - JohnEye

1 Answers

0
votes

hmmm, to make a permanent bouncing ball, Make your body BodyType.DynamicBody one, then just set the gravity to 0,EARTH (9.8f) and

scene.registerUpdateHandler(new IUpdateHandler() {


    @Override
    public void onUpdate(float pSecondsElapsed) {

            if(body.getPosition().y >=CAMERA_HEIGHT)
            {
                Vector2 v=new Vector2(0, -9f); //Adjust according to the bounce required
                body.setLinearVelocity(v);
            }

    }
});

The second one :

density is the volumetric mass density (),, and gravitational acceleration is independent of mass...

elasticity is the inertia when the object is stopped at a point, so if you don't want to move the body further just set it to 0

friction is the amount of the force resisting the relative motion of the body (like medium air, water or things like that)

So, to create a bouncing ball between two fixed points try setting (density=1, elasticity=0, friction=0)