有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java LibGDX Box2D防止对象在跳跃后减速

我正在用Box2D在libGDX中编写一个2d平台,我刚刚意识到,如果你的对象在跑步时跳跃,然后降落在一个表面上继续跑步,他会减速120%左右一秒钟。这真的很烦人,我真的想不出解决办法。我试着在运动员跳到地上后提高一秒钟的速度,但这似乎并不奏效。这是我用来移动玩家的:

    //jumping
    if(Gdx.input.isKeyJustPressed(Keys.SPACE) && player.b2body.getLinearVelocity().y == 0){
        player.b2body.applyLinearImpulse(new Vector2(0, 4.2f), player.b2body.getWorldCenter(), true);
    }

    //moving right
    if(Gdx.input.isKeyPressed(Keys.D) && player.b2body.getLinearVelocity().x <= 2){
        player.b2body.applyLinearImpulse(new Vector2(0.17f, 0), player.b2body.getWorldCenter(), true);
    }

    //moving left
    if(Gdx.input.isKeyPressed(Keys.A) && player.b2body.getLinearVelocity().x >= -2){
        player.b2body.applyLinearImpulse(new Vector2(-0.17f, 0), player.b2body.getWorldCenter(), true);
    }

Here是一段视频,显示正在发生的事情

我希望我提供了正确的信息,如果没有,请告诉我

编辑:我还尝试使用

    player.b2body.setLinearVelocity(1f, 0);

但这似乎让玩家滑翔到了右边


共 (0) 个答案