Java 2d:减缓旋转速度(如幸运之轮)

4

我正在尝试创建一个幸运轮盘游戏。

目前一切正常,但是我无法找到一个真实的方法来减缓轮子的旋转速度。

目前我只是尝试这样做:

    if (spin > 3) spin-=0.030;
    if (spin > 2) spin-=0.020;
    if (spin > 1) spin-=0.015;
    if (spin > 0.5) spin-=0.010;
    if (spin > 0) spin-=0.005;
    if (spin < 0) spin=0;

当然,这不是一个很好的方法,即使在这里和那里更改值,结果也不是很令人满意。

有什么数学函数可以逐渐减缓旋转速度呢?


https://physics.stackexchange.com/questions/163721/wheel-slowing-down-with-constant-acceleration - BackSlash
可能有关,或许也无关,但绝对是一篇非常有趣的阅读文章:https://stackoverflow.com/a/51904555/1531124 - GhostCat
2个回答

0
你可以尝试以下方法:
final float DECEL = 0.95;
final float FRICTION = 0.001;
spin = spin * DECEL - FRICTION;

假设这是在定期时间间隔内调用的。

额外的“- FRICTION”是为了使车轮实际停止。

如果您的绘图循环是根据上一帧绘制后的时间差调用的,则可以使用该时间差来调整DECEL和FRICTION参数。

例如,您可能会有:

final float DECEL = 0.95;
final float FRICTION = 0.001;
// calculate how much the wheel will slow down
float slowdown = spin - (spin * DECEL - friction);

// Apply the frametime delta to that
slowdown *= frameDelta;
spin = spin - slowdown;

当然,这需要对DECEL和FRICTION参数进行一些实验。

0

你可以尝试使用指数递减方程来模拟减速,该方程等于你的旋转速度。然后通过设置旋转时间的限制来停止旋转的轮子(因为在指数方程中y=0是一个渐近线)。

float spinSpeed;  //will track the spinning speed using an equation
double spinTime = 4;  //limits total spin time using an equation

for (i=1;i<=4;i++) {  //will track time in seconds
spinSpeed = math.pow[5.(-i+3)];  //equivalent  to y=5^(-(x-3))
}  //be sure to import math 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接