Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save Rope State
#5
OK so I have made some significant progress with saving the state of a rope that has been extended.

The long and the short of it is this:

1. I have a component that manages extending the Rope using the Rope Cursor. We are using a script which was provided a while ago to check for tension and extend the rope if tension exceeds a threshold.

2. If you do not use the rope cursor, saving and restoring rope state is pretty easy and can be summarized as:

* Pull velocity and position data from solver
* Serialize the positions and velocities of the rope in JSON or whatever
* To load - we attach an event handler to the OnAddedToSolver of the rope and in that event handler, we set the positions and velocities on the rope to the serialized values after Instantiate'ing our rope. We then call PushDataToSolver

3. after much experimentation, I found that in order to be able to easily save changes when the rope has been extended we only have to do one thing, each time we use the ChangeLength method of the cursor, we add that value to a list, we call the list lengthChanges and it's a List<float>. This list gets serialized with your positions and velocities data like usual.

4. When you load this data, the order is important: first - for each entry in your lengthChanges list, call ChangeLength on the rope cursor with that value. This is basically getting your rope back to the length it was when you serialized it. THEN - set your velocities and positions and push to solver.

It really is that easy.

TLDR - keep a list of each time you call ChangeLength on your rope cursor and serialize your lengthChanges, positions, and velocities. When deserializing, first, call ChangeLength for each entry in the lengthChanges list, then set your positions and velocities and push to solver.

NOTE: If you plan on serializing multiple times, it's important that you keep track of the lengthChanges list for multiple loads otherwise, it won't work. One optimization that we have done is during the resize code, if we are shrinking the rope and we are back to the ORIGINAL size of the rope, we clear out the length changes list so that it doesn't grow infinitely.

NOTE: You CANNOT just keep the final length of the rope and call ChangeLength once - this doesn't work for whatever reason, you need to call ChangeLength as many times as you called it originally even though the end length will just be the final length of the rope, the internal state will be correct.
Reply


Messages In This Thread
Save Rope State - by ptrick - 08-09-2017, 11:59 PM
RE: Save Rope State - by ptrick - 09-09-2017, 01:16 AM
RE: Save Rope State - by josemendez - 09-09-2017, 11:03 AM
RE: Save Rope State - by ptrick - 09-09-2017, 04:28 PM
RE: Save Rope State - by ptrick - 09-09-2017, 09:13 PM
RE: Save Rope State - by ptrick - 11-09-2017, 05:50 PM