Extrapolate Animation Curve (Endless game balancing curve)

172 Views Asked by At

I need a curve editor to make balancing of endless game then I tried to use AnimationCurve. I need to set a curve to a certain range ex. [0;1] and if I want a value over 1, the result of the Evaluation have to extrapolate the curve. I want to be able to compute Y from X and X from Y. The problem is AnimationCurve have only 3 WrapMode (Clamp, PingPong, Loop).

How to extrapolate an AnimationCurve ? Is there a better tool to make curve with extrapolation (post and pre curve) ?

1

There are 1 best solutions below

1
CBX_MG On

For real extrapolation I think you'd have to implement your own system based on Bézier mathematics. Me at least am not aware of unity providing it out of the box.

A work around for it could be to just define values beyond the 0 to 1 range to cover the extents, animation curves do allow this, I don't think there are to many issues with that.

Another solution, to stay in 0 to 1 range still but achieve the same effect, would be to model the curve from 0 to 1 so that it would cover extreme values within that range and remap the time for curve evaluation given by the object to a 0 to 1 range. E.g.:

// define range extents
float rangeMin = -5f, rangeMax = 5f;
var range = 10f;
// range could be calculated at runtime if necessary:
// [to] (higher value) - [from] (lower value) = [range]
// 5f - -5f = 10f

var timeRaw = 0; // variable provided value

var time01 = (timeRaw - rangeMin) / range;
// reult by timeRaw =  0: (0 - -5) / 10 = 0.5
// reult by timeRaw =  5: (5 - -5) / 10 = 1.0
// reult by timeRaw = -5: (-5 - -5) / 10 = 0.0

Combining both solutions allow you to cover even more extreme values.