fixed wrong dice rotation because of fps drop
This commit is contained in:
@@ -39,14 +39,15 @@ public DiceControl(AssetManager assetManager){
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void controlUpdate(float tpf) {
|
protected void controlUpdate(float tpf) {
|
||||||
|
float clampedTpf = Math.min(tpf, 0.05f); // Max 50 ms per frame
|
||||||
if (isRolling) {
|
if (isRolling) {
|
||||||
if(!slerp) {
|
if(!slerp) {
|
||||||
// Apply rotational velocity to the dice
|
// Apply rotational velocity to the dice
|
||||||
spinWithAngularVelocity(tpf);
|
spinWithAngularVelocity(clampedTpf);
|
||||||
|
|
||||||
// Gradually reduce rotational velocity (simulate deceleration)
|
// Gradually reduce rotational velocity (simulate deceleration)
|
||||||
angularVelocity.subtractLocal(
|
angularVelocity.subtractLocal(
|
||||||
angularVelocity.mult(deceleration * tpf)
|
angularVelocity.mult(deceleration * clampedTpf)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stop rolling when angular velocity is close to zero
|
// Stop rolling when angular velocity is close to zero
|
||||||
@@ -55,7 +56,7 @@ protected void controlUpdate(float tpf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
timeElapsed += tpf * rollDuration;
|
timeElapsed += clampedTpf * rollDuration;
|
||||||
|
|
||||||
|
|
||||||
if (timeElapsed > 1.0f) timeElapsed = 1.0f;
|
if (timeElapsed > 1.0f) timeElapsed = 1.0f;
|
||||||
@@ -71,7 +72,7 @@ protected void controlUpdate(float tpf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(spin){
|
}else if(spin){
|
||||||
spinWithAngularVelocity(tpf);
|
spinWithAngularVelocity(clampedTpf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user