mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-27 01:55:52 -05:00
Fix scoring lerp issue on story menu.
This commit is contained in:
parent
36a9c29720
commit
3975d34b70
2 changed files with 12 additions and 2 deletions
|
@ -311,7 +311,7 @@ class StoryMenuState extends MusicBeatState
|
|||
{
|
||||
Conductor.instance.update();
|
||||
|
||||
highScoreLerp = Std.int(MathUtil.coolLerp(highScoreLerp, highScore, 0.5));
|
||||
highScoreLerp = Std.int(MathUtil.smoothLerp(highScoreLerp, highScore, elapsed, 0.5));
|
||||
|
||||
scoreText.text = 'LEVEL SCORE: ${Math.round(highScoreLerp)}';
|
||||
|
||||
|
|
|
@ -62,12 +62,22 @@ class MathUtil
|
|||
* @param duration The total duration of the interpolation. Nominal duration until remaining distance is less than `precision`.
|
||||
* @param precision The target precision of the interpolation. Defaults to 1% of distance remaining.
|
||||
* @see https://twitter.com/FreyaHolmer/status/1757918211679650262
|
||||
*
|
||||
* @return A value between the current value and the target value.
|
||||
*/
|
||||
public static function smoothLerp(current:Float, target:Float, elapsed:Float, duration:Float, precision:Float = 1 / 100):Float
|
||||
{
|
||||
// var halfLife:Float = -duration / logBase(2, precision);
|
||||
// lerp(current, target, 1 - exp2(-elapsed / halfLife));
|
||||
|
||||
return lerp(current, target, 1 - Math.pow(precision, elapsed / duration));
|
||||
if (current == target) return target;
|
||||
|
||||
var result:Float = lerp(current, target, 1 - Math.pow(precision, elapsed / duration));
|
||||
|
||||
// TODO: Is there a better way to ensure a lerp which actually reaches the target?
|
||||
// Research a framerate-independent PID lerp.
|
||||
if (Math.abs(result - target) < (precision * target)) result = target;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue