How I kinda feel asking this question:
A few years back I created a new class for all my math because I got fed up with always mixing up “Mathf” and “MathF”, and that started me on a journey of developing better named and more powerful math functions and other little handy bits of logic that I find were sorely lacking in Unity.
And I began to ask myself, why is everything so poorly named and organized?
Aren’t these fundamental tools we use to generate our logic?
Here’s one example, “Mathf.clamp”. Why doesn’t this default to a value of 01? Why do we have to type in 0 and 1 if we want a 01 calp, or have to use “Mathf.clamp01”?
And why don’t we have more cool stuff to make our life easier?
I made this function called “FireAtZero” that I find super handy
public static bool FireAtZero(ref float value, float resetTimeLength = 0f, float timeScale = 1f)
{
if (value == -1) return false;
if (value == 0) { if (resetTimeLength > 0) value = resetTimeLength; else value = -1; return true; } //Check the single frame where value is 0
if (value > 0) value -= Time.deltaTime * timeScale;//Tickdown
else value = 0; //If not firing or counting down, defaults to -1 state
return false;
}
That I use all over the place:
if (zz.FireAtZero(ref _pulseTimer, timeBetweenPulse)) ResetPulse();
And what it does is sets off a function and then resets the timer to whatever it needs to be and it can be fired again.
Here’s one I just added now, often times I need to rescale or normalize a value around a new min/max, 9 times out of ten around a new 0 to 1 scale so i created this new function:
public static float Normalize(float val, float oldMin, float oldMax, float newMin = 0, float newMax = 1)
{
return newMin + (val - oldMin) / (oldMax - oldMin) * (newMax - newMin);
}
I guess my question is, is there some kind of library or script that has tons of useful gamedev features like this one that I don’t know about?
Or more at the topic at hand, why aren’t the included math functions out of the box easier to access, better named, and better polished towards the needs of gamedevs?
I could give a lot more examples of what could be improved, but it always seemed so odd to me that such core functionality that is so simple and easily upgraded is so… dated? Mediocre?
If there is a more polished, feature complete set of math functions with better naming conventions and usability and use cases, why isn’t it included with Unity out of the box?
I dunno. I’m pretty new to code obviously so this might be a really dumb question.