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 (x-axis), the game will provide y% (y-axis) 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.
Maths formula for the maths guru's
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
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 + (v2-v1)*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, (1-payout)*h)
end
end
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"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
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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
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)
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
- zorg
- Party member
- Posts: 3444
- 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: 3444
- 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! )
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Who is online
Users browsing this forum: Google [Bot] and 224 guests