# Creating a trend, and assigning point value to a variable :S

I may have bit off more than I can chew, (newbie) and any help to guide me in the right direction would be greatly appreciated.

1- I need to set var A and var B to specific values, based on var C. (easy enough…but)
2- As var C increases, the value of var A decreases based on a trend line
3- As var C increases, the value of var B increases based on a trend line

So my question is, how do you create trends to get values from, and then assign them?

I have 4 plot values for each of the variables, and var C will be manually controlled.

I guess an example would be: as my RPM increases (var C), down-force would decrease (var A), but turbo PSI would increase (var B).

OK thanks, I will look into how to use that. I came across it, but was worried it was not quite what I should use. Thanks again!

It’s weird to use, you have to pass in your independent variables as time. But the curve editor is powerful and indispensable for this type of work.

Yeah I can see that! I think it is going to take me some time to figure this out

Can the AnimationCurve still be used if the 3 variables are not used in an animation?

OK, I think I got part of it, my 3 variables are there with the 4 data points I have for each variable. Just need to work through this, figure out how to pull my values off it now…

I am down to 2 variables, and using time as my third. I can’t for the life of me figure out how to access the animation to get the values of my 2 variables based on the keyframe I specify. Any help would be greatly appreciated…

Forget about using an animation, you are simply trying to use the AnimationCurve. Here is some demo code to illustrate the idea. Assumes your curve goes from 0 to 1.

``````public class TestCurve  : MonoBehaviour {
[SerialiseFeild] AnimationCurve theCurve;

void Start (){
for (int i = -; i < 10; i++){
float x = theCurve.Evaluate(i/10);
Debug.Log(i.ToString() + " : " + x.ToString());
}
}
}
``````

Thanks again for your help! I came across this example yesterday, but not sure how to use it for what I need. (plus I am in Jscript).

I have a pretty big curve since I am plotting points with RPM as my scale (700 - 2500). As the RPM gets higher, my GPM gets lower, but PSI gets higher. these do not increase/decrease in a linear way, and I have very specific numbers for each at a given RPM.

I thought I had it figured out by using the time scale as my RPM (0-1800), and I plotted my GPM and PSI points which gave me 2 good curves to start with (until I can get additional plot points for each). My idea was to take my RPM variable, and set the keyframe to this value giving me the GPM and PSI for that RPM. Just couldn’t figure out how to set the keyframe and access the values.

You say there is a better way to do this (and I have come across many examples like the one above), I am just having a real hard time wrapping my head around how to use it lol. I fear this is going to take me quite some time to figure out!

This is pretty much exactly what I’m suggesting you do. Access the variables with AnimationCurve.Evaluate (RPM). You can set key frames in the inspector by double clicking on the curve.

1 Like

OK cool, so I was following I think maybe I was just burnt, had been coding all weekend, and when I got on that my brain was not co-operating lol

I tried to get the AnimationCurve.Evaluate to work, but kept getting errors. I was not coding it right (still learning). I am going to keep trying to get it. Thanks for the direction, at least I know I am pointed in the right direction!

Me again! I have been at this all week, and I still haven’t gotten it. I have been trying so may things but nothing is working. Any chance you could throw a dog a bone? I attached my script as well as my animation. I think I need to assign my animation to my " var curve : AnimationCurve;", but have no idea how…

2083806–136228–1250_RPM_GPM_PSI.js (226 Bytes)
2083806–136230–1250_RPM_GPM_PSI.rar (2.37 KB)

I still think we are on different pages. Here is the simplest example I could build. Hit play. Put a number in the input field between 1 and 0 and watch the text fields update themselves according to the animation curves. You can set the animation curves in the inspector.

You don’t have to use 0 to 1, I just made the curves that way.

1 Like

Thank you so much for your help. This whole time I have been using curves I made as an animation and trying to get it assigned to the curve in the Inspector lol I should be able to finally move forward this weekend, will let you know how it goes! Thanks again!

1 Like