Jump to content

[ANSWERED]floatCurves


Recommended Posts

What do you mean by 'create float curve function'? Can you give a bit more detail?

I'm looking for a way to get a result from a floatcurve with several nodes. I like to do something like


var result = new Unity.FloatCurve(new double[4][2] {{0,0.01},{0.2,0.1},{0.5, 0.5}{1,1}}).Evaluate(x);

Edited by FreeThinker
Link to comment
Share on other sites

No such luck for a one liner (you could ofc make your own to do so), although why you wouldn't be caching the resulting curve...?

FloatCurve curve = new FloatCurve();
curve.Add(0,0.1,0,0);
curve.add(0.2,0.1)
curve.add(0.5,0.5);
curve.add(1,1);
curve.Evaluate(x);

Edited by Crzyrndm
Link to comment
Share on other sites

Well, it was just an short illustration to make clear what I want. I want to create a Curve which I can use to get result given x. The curve would be created only once durrent initialisation and then called durring update.

Edit:

Perhaps I can do it unity AnimationCurve


public class ExampleClass : MonoBehaviour {
public AnimationCurve curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
void Update() {
transform.position.x = Time.time;
transform.position.y = curve.Evaluate(Time.time);
}
}

Link to comment
Share on other sites

FloatCurve are KSP class that uses Unity AnimationCurve. They don't have a useful constructor in .90 but AnimationCurve has :

var result = new AnimationCurve( new[] { new Keyframe(0,1), new Keyframe(1,5) }).Evaluate(0.5)

I just want to add that those object should be saved and doing that much new each frame, or worse in a loop, is an abomination :huh:

Edit : I took too much time to post :D

Edited by sarbian
Link to comment
Share on other sites

FloatCurve are KSP class that uses Unity AnimationCurve. They don't have a useful constructor in .90 but AnimationCurve has :

var result = new AnimationCurve( new[] { new Keyframe(0,1), new Keyframe(1,5) }).Evaluate(0.5)

I just want to add that those object should be saved and doing that much new each frame, or worse in a loop, is an abomination :huh:

Edit : I took too much time to post :D

Great, I think I now have the tools to achieve what I want. Now the only question left if to create some decent set of nodes, but it appears some special editors can help me with that. Thanks!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...