#AnimationCurve
1 messages · Page 1 of 1 (latest)
is sampling n points enough? and how many points to sample is enough?
You can use this code https://gist.github.com/keenanwoodall/c37ce12e0b7c08bd59f7235ec9614562
And regarding how many points, I guess it depends on how your curve looks. Maybe you can write your own baker for this NativeCurve, where you can specify number of points needed, but it will always require your manual imput
It is for a game server. If my server runs at 30ticks/second then probably 30 points/second is enough i think
My server is running at fixed time step
Does it makes sense?
{
public bool IsCreated => SampledCurve.IsCreated;
private NativeArray<float> SampledCurve;
public void Update(AnimationCurve curve)
{
if (curve == null)
throw new NullReferenceException("Animation curve is null.");
float duration = curve[curve.length - 1]
.time;
SampledCurve = new NativeArray<float>((int)(math.ceil(30.0f / duration)), Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
float t = 0f;
for (int i = 0; i < SampledCurve.Length; ++i)
{
SampledCurve[i] = curve.Evaluate(t);
t += (1 / 30f);
}
}```
like this
I have found this on internet
{
public AnimationCurveValueType CurveX;
public AnimationCurveValueType CurveY;
public AnimationCurveValueType CurveZ;
public int SegmentCacheX;
public int SegmentCacheY;
public int SegmentCacheZ;
public float3 Evaluate(float t)
{
return new float3(CurveX.Evaluate(t, ref SegmentCacheX), CurveY.Evaluate(t, ref SegmentCacheY), CurveZ.Evaluate(t, ref SegmentCacheZ));
}
public void Reset()
{
SegmentCacheX = 0;
SegmentCacheY = 0;
SegmentCacheZ = 0;
}
}``` with this (caching last segments) it is fast enough