首页 > 解决方案 > Java 3D 游戏:门打开太快

问题描述

我目前正在用 Java 制作 2.5D FPS 游戏。我的问题是当玩家与它们互动时门打开得太快了。我尝试了多种方法,例如使用计时器,但每次门立即完全打开。如何在关闭状态和打开状态之间实现平滑过渡?

这是我的门课:

public class DoorBlock extends SolidBlock {

    public boolean open = false;
    public double openness = 0;
    public double openLimit = 0.875;

    public static boolean useDoor = false;
    public int doorTimer = 0;

    public DoorBlock() {
        tex = 1;
    }

    public void tick() {
        super.tick();

        if (open)
            openness += 0.2;
        else
            openness -= 0.2;
        if (openness < 0)
            openness -= openness;
        if (openness > 1)
            openness = 1;

        if (openness < openLimit)
            blocksMotion = true;
        else
            blocksMotion = false;
    }

    //If the player opens the door
    public boolean use(StructureLoader level, Item item) {
        openness = openLimit;
        return true;
    }


    public boolean blocks(Entity entity) {
        return true;
    }
}

标签: java3d

解决方案


你在这里设置门立即打开

//If the player opens the door
public boolean use(StructureLoader level, Item item) {
    openness = openLimit;
    return true;
}

修改它以触发tick函数中的打开机制:

//If the player opens the door
public boolean use(StructureLoader level, Item item) {
    open = true;
    return true;
}

推荐阅读