我认为这是一个简单的错误,但是我已经崩溃了,想着它,我无法做到。 我不知道为什么当我与玩家一起跳跃并与另一个矩形(平台)碰撞时,玩家会出现在它上面。
for(RectangleMapObject rectangleObject : map.getLayers().get("platform").getObjects().getByType(RectangleMapObject.class)){
Rectangle rectangle = rectangleObject.getRectangle();
float x = rectangle.x;
float y = rectangle.y;
float width = rectangle.width;
float height = rectangle.height;
shapeRenderer.rect(x, y, width, height);
//TODO: Finish tile's physics
if(Intersector.overlaps(rectangle, nihanRect)) {
if (velocity.y > 0) {
nihan.getVelocity().y = 0;
nihan.getPosition().y = y - height - Constants.NIHAN_HEIGHT - 10;
nihan.setCollisions(false);
nihan.setAvailableJump(false);
} else {
nihan.getPosition().y = y + height - 0.5f;
nihan.setCollisions(true);
nihan.setAvailableJump(true);
if(Gdx.input.isKeyPressed(Input.Keys.Z)){
nihan.getPosition().y = y + height;
}
}
nihan.getVelocity().y = 0;
Gdx.app.log(TAG, "Collision produced!");
}else{
nihan.setCollisions(false);
}}
对不起,如果我的英语不好,我是一名西班牙语演讲者。 问候!
When the player is standing - > After jumping the player appears in the top of the platform
答案 0 :(得分:0)
我将变量“velocity.y”更改为“nihan.getVelocity.y”