Hello maths experts  in my current project I have modelled a rewards system where delivering x% of the goal will deliver y% of the reward but not on a linear scale. I've done a graph in excel and included the data for the graph and I'm hoping you brainy people can help me determine the equation so that:
when a player delivers x% of the required outcome (xaxis), the game will provide y% (yaxis) of the total available reward.
The required curve is NOT the blue line. Please see the red line and the data that creates it. It is intentionally curved so that 'payoff' happens about 65% (doesn't have to be exact).
The formula you see is the MS Excel trend line (ignore the error  I couldn't remove that one) but it really means nothing to me.
Maths formula for the maths guru's
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Maths formula for the maths guru's
If it's not important that it's a smooth curve, you could instead simply imagine a straight line between the given points and use linear interpolation to determine the payout. That way you can easily have any arbitrary shape of the "curve". Also, minimal math involved!
Code: Select all
local function lerp(v1, v2, t)
return v1 + (v2v1)*t
end
local function getPayout(payouts, delivered)
local iFloat = delivered * #payouts
local iLow = math.floor(iFloat)
local iHigh = math.ceil(iFloat)
return lerp(payouts[iLow], payouts[iHigh], iFloat%1)
end
local payouts = {[0]=0, .02, .05, .12, .25, .40, .57, .75, .90, .98, 1}
function love.draw()
local w, h = love.graphics.getDimensions()
love.graphics.line(0, h, w, 0)
for x = 0, w do
 'delivered' and 'payout' are values between 0 and 1.
local delivered = x / w
local payout = getPayout(payouts, delivered)
love.graphics.points(x, (1payout)*h)
end
end
Tools: Hot Particles, LuaPreprocess, (more) Games: Momento Temporis: Light from the Deep, Energize!
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: Maths formula for the maths guru's
Not sure, but pretty similar:
https://www.desmos.com/calculator/5rl0vfpada
https://www.desmos.com/calculator/5rl0vfpada
 Attachments

 20210721T09_18_20Desmos _ GrafikRechner.png (64.36 KiB) Viewed 2255 times
Re: Maths formula for the maths guru's
Thanks DF.
No, a smooth curve is not necessary. I just thought a single formula = 1 line of code. I'll adapt what you've suggested. Thanks.
No, a smooth curve is not necessary. I just thought a single formula = 1 line of code. I'll adapt what you've suggested. Thanks.
Re: Maths formula for the maths guru's
Here's another option that accomplishes roughly the same thing using a logistic function instead.
https://www.desmos.com/calculator/rbkoh0hjwc
To do e^x in Lua, use math.exp(x) (I had to look that up, LOL)
https://www.desmos.com/calculator/rbkoh0hjwc
To do e^x in Lua, use math.exp(x) (I had to look that up, LOL)
 Attachments

 Screenshot_20210721_110040.png (30.51 KiB) Viewed 2199 times
 zorg
 Party member
 Posts: 3115
 Joined: Thu Dec 13, 2012 2:55 pm
 Location: Absurdistan, Hungary
 Contact:
Re: Maths formula for the maths guru's
The wanted curve looks like two sinusoidal curves, connected at the x = 60% point. it could probably be implemented by using such easing functions and adjusting the range and domain of them (scaling the input & output).
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Maths formula for the maths guru's
Two connected sine curves is just one cosine curve
 zorg
 Party member
 Posts: 3115
 Joined: Thu Dec 13, 2012 2:55 pm
 Location: Absurdistan, Hungary
 Contact:
Re: Maths formula for the maths guru's
Feel free to demonstrate to me how you skew the two parts of it differently
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Maths formula for the maths guru's
Re: Maths formula for the maths guru's
I'm curious what you're getting at, Zorg. Are you talking about 2 separate sin (or cos) curves and using an if/else scenario to decide which to use? Or do you have a meaningful way to combine them into 1 function? I'd love to see the algorithm you're thinking of. (And I'm pretty sure we're also way beyond what togFox looking for, haha! )
Who is online
Users browsing this forum: No registered users and 15 guests