• Runtimes
  • Suggestion: Resting physics support

Hello!

When we enter a scene or a saved game, we wish to forward the physics updates to a state where the object is resting. How would I go about that? Currently, I am checking the different velocities of each constraint, and if any of them have a velocity above a certain value, I update again. This works, but a method like updateUntillRest or something would be really helpful, and could probably be optimized in better ways.

Secondly, once the skeletons reach the resting positions, we have no need to update them. If we could get that info, perhaps as a return value of updateWorldTransform or as a property on the constraints, that would be really useful.

Thanks!

Related Discussions
...

To achieve a resting state for physics in Spine, you can continue using your current method of checking velocities and updating until they fall below a certain threshold. This approach is effective, though it may require some manual tuning to determine the appropriate velocity threshold for your specific use case. Unfortunately, Spine does not currently offer a built-in method like updateUntilRest. However, you can optimize your current method by ensuring that physics updates are only performed when necessary, potentially by subclassing and overriding methods to control when updates occur.

Regarding the second part of your question, once the skeletons reach their resting positions, you can indeed stop updating them. While Spine does not provide a direct return value from updateWorldTransform to indicate a resting state, you could implement a custom solution by tracking the velocities of your constraints and setting a flag when they are all below your defined threshold. This flag could then be used to skip further updates until a change in state is detected.

You could step the physics forward many times, without rendering any of it. Do it enough times to cover the amount of time needed for your physics to rest. This is easier than checking velocities.

You'd do that by advancing the skeleton time with Skeleton update, then call updateWorldTransform(Physics.update) to apply physics and update the bone transforms, which are needed for the next physics update. Repeat until you're sure the physics has settled.

If you move your skeleton a large distance, it will likely cause physics to sproooing. You can reset physics so this doesn't happen. You could also reset physics and reset the skeleton to the setup pose (or an animation pose) then step it many times as I described. By starting at a known pose, you can be more sure about how long you need to step the physics.

Stepping the physics like this is common. It is needed if you want to start showing an animation or pose and don't want to see the physics transition from the setup or old pose.

I expect you can step many times (eg likely 3000+ steps) before performance is an issue. Spine does similar stepping every frame, from frame zero to the current frame, for the Deterministic physics setting.

It's quite easy to do with the existing API. A method to "update until rest" (or "is resting") is tricky, because some physics setups will never come to a rest, or the rest values could vary compared to other setups.

    Nate
    Thanks for the answer, I see that having damping at 0 for instance can indeed produce infinite loop.
    I think my solution will be to set a defined pose, call update on the skeleton with a big enough delta time, followed by calling updateWorldTransform(Physics.update). At this point, I will assume the physics is at a resting point. So, basically what you suggested 😃

    Yep, 0 or low damping can prevent reaching a resting state. Multiple physics constraints can also interact and oscillate for a long time.

    Your approach can work in some cases. Spine's physics uses a fixed time step, so with a single large delta it will step each physic constraint many times internally. However, other bone world transforms are not computed for each of those sub-steps, so the stepping won't consider all of the potential movement throughout the bone hierarchy. If you are applying an animation (I don't think you are, since you mentioned freezing the pose) and/or have physics bones with other physics bones under them, or otherwise have constraints that affect physics bones, then the result of one big step won't be the same as taking smaller steps and calculating all the bone world transforms at each step.

    If one big step works for you, then it's fine. If you want to "fast forward" physics while taking everything into account, especially while playing animations, then you'd want to take many smaller steps with updateWorldTransform between them.

    I do have bones with physics in a nested hierarchy, so that may require updating in multiple steps. In time we also aim to have nested spine files, each applying physics to nested bones, so we would probably have to use an update loop where we update from the root spine (using multiple updated in order to update nested bones), updating down a tree of nested spine files. Should be doable though.

    • A Nate le gusta esto.