I'm making a cooking game and one of the minigames in the game is to put ingredients on a barbeque. As it's being cooked, a progress bar is displayed, with a range between 0-1.
The goal is to take it off the barbeque at the "perfect point", which would give you a score between 1-5, in the form of a star rating. The "perfect point" in my example image is 0.5, but could vary between ingredients, so it can for example be closer to 1, when the ingredient is burned/destroyed.
Also depending on the difficulty of the ingredient, the slope to get a 5 star rating can be narrower (red line) which makes it harder or broader (green line) which makes it easier. This is currently set as the factor variable in the code below.
What mathematical function can I use to get a shape more like the image? Also, can you recommend an online tool to visualize the curve and how the values change it?
I'm currently using the code below, but I don't like that much how it works:
// The result is then capped between 0-1 and remapped to 1-5 stars, // but that's not important for this question. :) // Varies based on user input float progress = 0.4f; // Set per ingredient float perfectPosition = 0.5f; float factor = 1.3f; // Calculation float distFromPerfectPosition = Mathf.Abs(perfectPosition - progress); float result = 1 - Mathf.Pow(distFromPerfectPosition, factor);
Thank you in advance!