0

我认为我的碰撞有问题,通常如果你与一个平台发生碰撞,我有它,所以它就像流沙一样。但是,如果平台太小,它不会达到 x 或 x + 宽度,并且 y 也相同,因此玩家会快速摔倒。我该如何解决这个问题?

http://www.taffatech.com/Platformer.html

这是我的碰撞代码:

for (var i = 0; i < Platforms.length; i++) {

    if (Player.x > Platforms[i].x 
        && Player.x < (Platforms[i].x + Platforms[i].width)) {

        if (Player.y + (Player.height) > Platforms[i].y 
            && Player.y < Platforms[i].y + Platforms[i].height) {

            Player.jumping = false;
            Player.playerColour = "orange";
            Player.velY = 0;
            Player.velX = 0;
        }
    } else {
        gravity = 0.3;
    }
}
4

1 回答 1

0
playerWidth = width of the square the player moves; //assign your value here
for (var i = 0; i < Platforms.length; i++) {

if (!(Player.x < (Platform[i].x-playerWidth) || (Player.x > (Platform[i].x+Platform[i].width)))) {

    if (!(Player.y < (Platform[i].x-playerHeight)) || Player.y > (Platform[i].y+Platform[i].height))) {

        Player.jumping = false;
        Player.playerColour = "orange";
        Player.velY = 0;
        Player.velX = 0;
    }
    } 
else {
    gravity = 0.3;
}
}

让我知道这是否有效,否则如果我们错过了某些情况,我们必须尝试其他方法。是的,顺便说一句,恭喜你,你正在建立一个非常好的概念,继续前进。

于 2013-06-22T17:50:54.590 回答