I have 2 basic float variables; distance and damage. The damage variable changes based on the distance variable. At the moment I have several damage variables due to the number of times the damage changes over distance (eg. 50 dmg between 0-20m, 30 dmg between 20-40m etc).
I noticed that the standard asset FPS controller uses an animation curve to control its slope curve modifier. I have never used the animation curve variable type, but I’m wondering if it is possible to use it for my particular case? For example, if I could make the y axis = damage, and the x axis = distance then I could create a single animation curve that represents this instead of having 6 separate variables. Is this possible with animation curves?
I have had a look at the FPS controller script but I do not quite understand how it is using the animation curve to read values from it and translating those into logic. I think it might involve the Evaluate function but there isn’t an example in the docs.
Ok I have managed to work this out. It is a bit confusing and isn’t properly explained anywhere but here goes. First you need to declare an AnimationCurve variable. Then open the curve editor of this variable and use the Y axes for damage and the X axes for distance. Create your keyframes depending on how you want the damage to change over distance. Then you simply need to make the damage equal to the AnimationCurve evaluated. Here is a snippet to demonstrate this:
I want to achieve the same thing and this really helped me out.
Thing is, the numbers I’m working with are larger than 0-1. What I’m doing is calculating air density, with the altitude range being 0-3500 meters. How can I rescale the curve to fit?
Personal tip: normalize your curves. It’s far easier to do the math if X and Y are both 0-1, and your multipliers are elsewhere (other editor variables, probably, but just as easily coming from completely different systems).