Align to Spline using real-world speed
I’m attempting to make an improved align to spline xpresso setup that allows me to set a real-world speed of an object that follows a spline.
In the simplest use-case (with arbitrary numbers for a clearer explanation), I created a spline along a road object. I also have a car object in a null. Instead of using the standard align to spline, I’d like to keyframe the speed of my car object (as it moves along the spline) from 0 cm/second to 1600 cm/second over the first 2 seconds. I then want it to stay at that speed until 6 seconds, when it slows to 250 cm/second during a turn, then accelerates back to 1600 cm/second. Then at 12 seconds, it begins to decelerate to 0 cm/s over the next 2 seconds.
I managed to make this happen in Xpresso with a node structure that takes a starting point along the spline (set via user data), an initial speed (set via user data), calculates the per-frame movement necessary with that speed, identifies the current position of null, and then calculates and sets the new position of the null. This works as I had hoped, however, it only works when playing forward. If the timeline is scrubbed or you move back a frame, it breaks.
I also built a rig in which the initial speed, acceleration, max speed, start time of deceleration, and rate of deceleration were manually entered. This was vastly more complicated both to build and use. What’s more, it only allowed for a single acceleration and deceleration. However, because acceleration, max speed, and deceleration were defined, the position at any given point could be calculated as a function. This allowed me to set that position independent of playback direction, which allowed easy, reliable scrubbing.
Is there a way to make my rig which uses only speed work independent of playback? I’m attaching that rig below.
It looks like one option is to setup and animate my scene, add it to the Dope sheet, and bake the object. This works, putting a keyframe on every frame and removing the xpresso. However, I'd much prefer an option that remains editable.
Dr. Sassi last edited by
I'm unaware that one could disconnect the content from the timeline and have real-time working while also asking to srub back the timeline that holds keyframes for the whole execution.
This sounds more like something for game engines, and Cinema 4D is not one of them by default.
One more thought: Things will get more complicated when the Spline is a curve. If it is only a straight direction, P.X., for example, why use a spline?
The next question would be, how do you define acceleration? It is typically not a linear process. So, defining that by time needs a formula that also expresses this curve-like behavior.
I think that there is an option. Still, you might check in the Developer Café, as you like to do something that needs to store a lot of data to mark the actual starting time, then calculate what happens with the time points you mentioned and have the real-time representing it on the screen, while refreshing and played needs to be ignored.
In the Q&A forum, my reply is: Bake it as Alembic, and bake again when changes are needed. But no, Alembic is not time-independent.
A tip for the XPresso setup: Sort the XManager from top to bottom in how the information flows. Otherwise, you might have a priority issue at one point.
What Cinema 4D is built is an animation system that targets the rendering results. Check Unreal or Unity for those needed extended options.
My best wishes for your project