java - 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;
}
}
解决方案
你在这里设置门立即打开
//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;
}
推荐阅读
- excel - 将过滤后的数据从一个工作表复制并粘贴到另一个工作表
- c++ - 在 C++ 中,与数据结构指针相比,数据结构有多“重”?
- sql - 更改 Oracle 表以添加日期时间列,该列默认为新的当前时间或更新到记录
- angular - 角度模拟 Maticon
- vba - 有没有办法使用 VBA 在 Word 中插入复选框和文本框?
- android - 将字符串和整数从 Activity 传递到 Fragment
- django-rest-framework - 目前在 Django rest 从事一个送餐项目。我需要导入 CSV 文件
- assembly - 大会比较数字
- css - 线性渐变和旋转在 Safari 上产生问题
- windows - Powershell 为什么无法合并我的 csv 文件?