Saturday, October 8, 2022
HomeGame Developmentarithmetic - Formula to assign star ranking primarily based on cooking time...

# arithmetic – Formula to assign star ranking primarily based on cooking time over/underneath goal

I’m making a cooking sport and one of many minigames within the sport is to place substances on a barbeque. As it is being cooked, a progress bar is displayed, with a variety between 0-1.

The purpose is to take it off the barbeque on the “good level”, which might offer you a rating between 1-5, within the type of a star ranking. The “good level” in my instance picture is 0.5, however might fluctuate between substances, so it may for instance be nearer to 1, when the ingredient is burned/destroyed.

Also relying on the problem of the ingredient, the slope to get a 5 star ranking could be narrower (purple line) which makes it more durable or broader (inexperienced line) which makes it simpler. This is at present set because the issue variable within the code under.

What mathematical perform can I exploit to get a form extra just like the picture?
Also, are you able to advocate a web-based software to visualise the curve and the way the values change it?

I’m at present utilizing the code under, however I do not like that a lot the way it works:

``````// The result's then capped between 0-1 and remapped to 1-5 stars,
// however that is not vital for this query. :)

// Varies primarily based on consumer enter
float progress = 0.4f;

// Set per ingredient
float perfectPosition = 0.5f;
float issue = 1.3f;

// Calculation
float distFromPerfectPosition = Mathf.Abs(perfectPosition - progress);
float end result = 1 - Mathf.Pow(distFromPerfectPosition, issue);

``````

Thank you prematurely!

RELATED ARTICLES