Changing Key Values on the Fly

The SequenceInstance object has a few fields that can be set in either the Sequence object or the Effect object. These are SequenceInstance.Inertia, SequenceInstance.Elasticity, SequenceInstance.StartValue, and SequenceInstance.EndValue. It also have variables for SequenceInstance.Velocity and SequenceInstance.CurrentValue.

  1. In the Sequence object, Inertia and Elasticity set the initial values for these fields. However, by changing the values for Inertia and Elasticity in the SequenceInstance object you can change these values on the fly. There is a good demonstration of how that is done in Demo #1. In fact, if you were so inclined, you could pass one effect’s SequenceInstance as the reference variable of another effect and run an effect on the Inertia and Elasticity to make their values change over time. This could be used to create really interesting mechanics, like a car whose controls got more and more squishy the longer you tried to drive it.
  2. The Effect object has methods to RetrieveStartValue and RetireveEndValue. The result of those two actions are stored in the SequenceInstance under StartValue and EndValue. You can change the StartValue and EndValue while the sequence is running and the position will be updated as if those were always the StartValue and EndValue. As an example, lets take a simple Effect that runs a float from a StartValue of 1.0 to an EndValue of 2.0. If our effect happens to be 50% done and we change StartValue to -2.0 then the current value will jump from the 1.5 it is currently at to 0.0. Smoothing can smooth out that transition so that it moves over to the new position over several frames, but even with smoothing it’s a good idea to change StartValue or EndValue gradually and not make them jump around too much.
  3. SequenceInstance.CurrentValue is the current value after all smoothing effects. If no smoothing effects are enabled then changing this value won’t accomplish much, since it will just jump back into position instantly. However, if you have something like Elasticity enabled then changing CurrentValue can be somewhat like pulling on a rubber band.. as soon as you release it the effect will bounce back into place. This can be useful since it will have little or no effect on the eventual path of the object, but can give your app a good deal of juiciness.
  4. You won’t see a result from changing SequenceInstance.Velocity unless Elasticity is enabled. If you change it while Elasticity is enabled then you’ll see your object fly off in the direction you specified and then turn around and come back. Once again, as an example, if you had a zipline running along a track and something came by and hit the zipline from the side then you could transfer the intruding object’s velocity into the zipline and it would bounce back and forth on it’s track.