Trying to use the splines package to dynamically evaluate position based on an animation curve

Hi guys,
In my C# project, I have a series of racers. I have a spline for each racer, and each racer progresses along this at a rate determined by an Animation Curve (acceleration is determined by evaluating the curve over time). This means no pre-existing animations are needed.

I am trying to port this for use with Needle engine, however I am struggling as Needle doesnt expose a series of functions used in these Unity spline classes such as EvaluatePosition(), EvaluateTangent(), EvaluateUpVector() from the SplineUtility.cs script, which in turn uses other functions in the SplineUtility and the CurveUtility class.

I looked at the spline example in the samples, and am not really understanding its use as it all seems based on pre-defined animations, which is the complete opposite use case of what I want to use it for.

I’ve included my C# code to show what I am trying to recreate.

private System.Collections.IEnumerator SimulationRoutine(IReadOnlyList<Participant> participants)
        {
            float elapsed = 0f;
            while (elapsed < m_ParticipantConfig.CompletionTimeMax)
            {
                elapsed += Time.deltaTime;
                foreach (var participant in participants)
                {
                    Spline spline = participant.Spline;
                    GameObject runner = participant.Target;
                    float completion = participant.CompletionTime;
                    float progress = Mathf.Clamp01(elapsed / completion);

                    Vector3 position = spline.EvaluatePosition(m_ParticipantConfig.AccelerationCurve.Evaluate(progress));
                    runner.transform.position = participant.PathOffset + position;

                    var remappedForward = Vector3.forward;
                    var remappedUp = Vector3.up;
                    var axisRemapRotation = Quaternion.Inverse(Quaternion.LookRotation(remappedForward, remappedUp));

                    var forward = Vector3.Normalize(spline.EvaluateTangent(progress));
                    var up = spline.EvaluateUpVector(progress);
                    runner.transform.rotation = Quaternion.LookRotation(forward, up) * axisRemapRotation;;
                    
                }

                yield return 0;
            }

          
        }

Any nudge in the right direction is appreciated.

Hello, nostalgicbear! I’m an AI-powered assistant here to help you with your questions about Needle Engine, three.js, and basic Unity or Blender support. Please share your question, including details like your OS, Needle Engine version, and any Unity or Blender versions you are using, so I can assist you further!

2 replies left - GPT 4O
thread_7NcaSHl3DaQsoruAiGbR4JIl
Reply to this message to continue the conversation

Hi,

the samples scene splines is not a baked animation but evaluates the position on a spline given a position T in the range 0 - 1. The SplineContainer class handles that.

The sample just animates that position with an AnimationClip but it can be fully dynamic too (which is what we do on needle.tools for example)

image

1 Like

Thanks Marcel. I think I was initially thrown by this due to the issue you just resolved for me on another thread. I had tried updating some values in a script and they hadnt taken affect due to the β€œdefault” keyword. That made me think something I was doing was wrong related to splines. Late night programming at its finest.

This makes sense, and the updating solution reading from a curve is working now. Appreciate the help as always.

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.