简体   繁体   中英

Libgdx Box2D Velocity is just not fast enough

I have a rectangle that I would like to move fast but for what ever reason the faster velocity I use still seems slow. What am I doing wrong? I have also dropped a circle from above onto a surface and even tough I play with gravity it comes down like a ballon...

Some declarations

float velocity = 10000000f;
static final float BOX_STEP=1/60f;  
static final int BOX_VELOCITY_ITERATIONS=6;  
static final int BOX_POSITION_ITERATIONS=2;  

Gravity, tried everything and they all seem to suck

world = new World(new Vector2(0, -50), true);

The ground my object is moving onto

    //ground
    BodyDef groundBodyDef =new BodyDef();  
    groundBodyDef.position.set(new Vector2(0, camera.viewportHeight * .08f));  
    Body groundBody = world.createBody(groundBodyDef);  
    PolygonShape groundBox = new PolygonShape();  
    groundBox.setAsBox((camera.viewportWidth) * 2, camera.viewportHeight * .08f);  
    groundBody.createFixture(groundBox, 0.0f);   

And then here are my objects:

    //ball
    bodyDef = new BodyDef();  
    bodyDef.type = BodyType.DynamicBody;  
    bodyDef.position.set(new Vector2(camera.viewportWidth * .2f, camera.viewportHeight * .75f));  
    body = world.createBody(bodyDef);  
    CircleShape dynamicCircle = new CircleShape();  
    dynamicCircle.setRadius(camera.viewportWidth * .035f);  
    FixtureDef fixtureDef = new FixtureDef();  
    fixtureDef.shape = dynamicCircle;  
    fixtureDef.density = 0.5f;  
    fixtureDef.friction = 0.5f;  
    fixtureDef.restitution = 0.8f;  
    body.createFixture(fixtureDef); 
    body.setLinearVelocity(0,-100);

    //slime boy
    BodyDef bodyBoxDef = new BodyDef();  
    bodyBoxDef.type = BodyType.DynamicBody;  
    bodyBoxDef.position.set(new Vector2(camera.viewportWidth * .08f,camera.viewportHeight * .191f));  
    bodyBox = world.createBody(bodyBoxDef);  
    PolygonShape slimeBox = new PolygonShape();  
    slimeBox.setAsBox(camera.viewportWidth * .04f, camera.viewportHeight * .03f);
    FixtureDef fixtureSlimeDef = new FixtureDef();  
    fixtureSlimeDef.shape = slimeBox;  
    fixtureSlimeDef.density = 1.0f;  
    fixtureSlimeDef.friction = 0.0f;  
    fixtureSlimeDef.restitution = 0.0f;  
    bodyBox.createFixture(fixtureSlimeDef);  

    debugRenderer = new Box2DDebugRenderer(); 

    body.applyTorque(1000000000);
    bodyBox.setFixedRotation(true);
    bodyBox.setBullet(true);

Any one have suggestions to speed up all movement in this?

I have been using a screen 1280 by 720 but I saw from other sources smaller is better so I scaled down to 640 by 260 but still not the preformance I want. How small should I really go?

From the Box2d Manual (Section 2.2):

Box2D is tuned for meters, kilograms, and seconds. So you can consider the extents to be in meters. Box2D generally works best when objects are the size of typical real world objects. For example, a barrel is about 1 meter tall. Due to the limitations of floating point arithmetic, using Box2D to model the movement of glaciers or dust particles is not a good idea.

See https://stackoverflow.com/a/4556714/960524

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM