Skip to content

Instantly share code, notes, and snippets.

@paulorenanmelo
Last active May 7, 2025 16:12
Show Gist options
  • Save paulorenanmelo/6618b2b07e6ab47b0e2193d27025cbb8 to your computer and use it in GitHub Desktop.
Save paulorenanmelo/6618b2b07e6ab47b0e2193d27025cbb8 to your computer and use it in GitHub Desktop.
Number Extensions
public static class NumberExtensions
{
public static float Smooth(float amount, float start, float end)
{
// Clamp to 0-1;
amount = (amount > 1f) ? 1f : amount;
amount = (amount < 0f) ? 0f : amount;
// Cubicly adjust the amount value.
amount = (amount * amount) * (3f - (2f * amount));
return (start + ((end - start) * amount));
}
public static float Remap(float val, float in1, float in2, float out1, float out2)
{
return out1 + (val - in1) * (out2 - out1) / (in2 - in1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment