Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Extrapolate Animation Curve (Endless game balancing curve)

Discussion in 'Scripting' started by Karrix, Jan 15, 2023.

  1. Karrix

    Karrix

    Joined:
    Feb 10, 2019
    Posts:
    10
    Hi,

    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) ?
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,531
    Unity's AnimationCurve is using bezier splines. You can not extrapolate them meaningfully since such a curve is non linear and may or may not end in a tangent. So the only meaningful extrapolation would be linear. Trying to extrapolate a bezier curve any further than a little bit behind its last point would result in complete garbage for most surves. They are interpolation splines and are only defined inside their range.

    For balancing an endless game, a level up system or anything else that requires an asymptotic behaviour, you usually would model your curve through an exponential function. The main reason for this is that e^x is it's own derivative so it's very easy to get any order of derivatives. Also it's the basis of any natural growth.

    Though it completely depends on your usecase.

    ps: technically you can extrapolate any bezier curve since it's just a polynomial. However the result would certainly not be what you may expect. If you want to use an AnimationCurve, you could insert a keyframe way outside the 0 - 1 range and model some asymptotic tendency. Once you go outside the range of the animation curve, you just manually continue linearly along the tangent. As long as you model your curve that the last bit becomes almost asymptotic, just grabbing two values at the very end of the curve and using it as tangent would be the easiest and cheapest solution.
     
    Karrix likes this.
  3. Karrix

    Karrix

    Joined:
    Feb 10, 2019
    Posts:
    10
    Thanks for your answer :)
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Check out some videos on "design game difficulty curve..." sometimes it's better to have a curve that rises for a while, then falls back, then rises more, falls back less, etc.

    One term for this is a sawtooth curve, or another is "dragons tail" with the triangular scales of the dragon tail going upwards.

    This type of a difficulty helps "change up" the experience, giving the user a brief pause before tackling the next "Stage" of difficulty.
     
    MaskedMouse and DragonCoder like this.