2016-07-27 1 views
1

나는 플래터 폼 게임을 만들고 있는데, 이제는 플레이어의 움직임을 만들고 있습니다. 그래서 'A'를 누르면 플레이어가 왼쪽으로 이동합니다 (player.moveLeft()). 'D'를 누르면 플레이어가 rigth (player.moveRigth())로 이동합니다. 'W'를 누르면 플레이어가 점프 (player.jump())됩니다. 플레이어가 이동 계속, 내가 점프하기 전에 'A'또는 'D'를 누르면, 플레이어가 점프 할 때 나는 키를 놓을 :libGDX (Box2D)에서 신체의 충격과 힘은 멈추지 만 중력은 멈추는 법?

public void moveLeft() { 
    if(Gdx.input.isKeyPressed(Keys.A) && 
     !Gdx.input.isKeyPressed(Keys.D) && 
     body.getLinearVelocity().x > -MAXIMUM_VELOCITY){ 
     left = true; 
     body.applyLinearImpulse(-3, 0, body.getPosition().x, body.getPosition().y, true); 
    }else if(Gdx.input.isKeyPressed(Keys.D) && 
      Gdx.input.isKeyPressed(Keys.A) && 
      !inTheAir){ 
     stop(); 
    }else if(!Gdx.input.isKeyPressed(Keys.A) && 
      !Gdx.input.isKeyPressed(Keys.D) && 
      !inTheAir){ 
     stop(); 
    } 
} 

public void moveRigth() { 
    if(Gdx.input.isKeyPressed(Keys.D) && 
     !Gdx.input.isKeyPressed(Keys.A) && 
     body.getLinearVelocity().x < MAXIMUM_VELOCITY){ 
     rigth = true; 
     body.applyLinearImpulse(3, 0, body.getPosition().x, body.getPosition().y, true); 
    }else if(Gdx.input.isKeyPressed(Keys.D) && 
      Gdx.input.isKeyPressed(Keys.A) && 
      !inTheAir){ 
     stop(); 
    }else if(!Gdx.input.isKeyPressed(Keys.D) && 
      !Gdx.input.isKeyPressed(Keys.A) && 
      !inTheAir){ 
     stop(); 
    } 
} 

public void stop(){ 
    body.setLinearVelocity(0, 0); 
    body.setAngularVelocity(0); 
} 

public void jump(){ 
    if(!inTheAir && Gdx.input.isKeyPressed(Keys.W)){ 
     inTheAir = true; 
     body.setLinearVelocity(0, 0); 
     body.setAngularVelocity(0); 
     body.applyLinearImpulse(0, 7, body.getPosition().x, body.getPosition().y, true); 
    } 
} 

그것은 작동하지만 문제가 생겼어요. 어떻게 해결할 수 있습니까 ?? 도와주세요 !!

Vector2 vel = body.getLinearVelocity(); 
vel.x = 0f; 
body.setLinearVelocity(vel); 

이 방법은, Y 축 속도가 그대로 유지하지만 플레이어가 옆으로 이동하지 않습니다 :

답변

1

당신은 X 축 속도를 조작 할 수 있습니다.

+0

정말 고마워요. :디 – Lordeblader

관련 문제