FlowCanvas Forums › Support › Transfer bone values with delay › Reply To: Transfer bone values with delay
Hello again and sorry for the late reply.
I’ve just manage to create this node you requested as well as a damp node (for floats and vectors).
Since I find them to be useful and will be included in the next, the best way for you to use them now would be to open up the file “Time.cs” and copy/paste the following code in there instead of sending you a separate package file.
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
[Category("Time")] [Description("Input values are buffered and returned in order of buffering once the buffered amount reaches the buffer size. In practice this creates a delayed value output when the node is constantly updated per-frame.\nWhen the node ceases to update, a new buffer is created.")] [ExposeAsDefinition] public class Buffer<T> : PureFunctionNode<T, T, int> { private int lastFrame = -10; private Queue<T> q; public override T Invoke(T value, int size = 60) { var currentFrame = Time.frameCount; //init if (currentFrame - lastFrame > 1){ q = new Queue<T>(); } lastFrame = currentFrame; q.Enqueue(value); return q.Count >= size? q.Dequeue() : q.Peek(); } } [Name("Damp (Float)")] [Category("Time")] [Description("Returns a smoothly interpolated value towards the input value.")] public class DampFloat : PureFunctionNode<float, float, float>{ private float last; public override float Invoke(float value, float damp = 1f){ last = Mathf.Lerp(last, value, damp * Time.deltaTime); return last; } } [Name("Damp (Vector3)")] [Category("Time")] [Description("Returns a smoothly interpolated value towards the input value.")] public class DampVector3 : PureFunctionNode<Vector3, Vector3, float>{ private Vector3 last; public override Vector3 Invoke(Vector3 value, float damp = 1f){ last = Vector3.Lerp(last, value, damp * Time.deltaTime); return last; } } |
Simply paste the code anywhere within the Time.cs file and within the namespace brackets of course.
There is a big difference between Buffer and Damp of course:
– Buffer, will output the exact input value in the exact order they were queued. Buffer also works with all types.
– Damp, will instead output an interpolated value (float or Vector) towards the input value.
Let me know if this works for you.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh