Motion Manager
Description
The Motion Manager script is the main component in the asset, it does the following things:
Keeps track of objects and the forces applied to them.
Makes sure the forces affect those objects.
Allows developer's easy access to those objects.
Every object that needs to have a Spring System will have to subscribe itself to this component at the start of the game; that way the Motion Manager will take care of calculating its rest point for further spring calculations.
Usage
To subscribe an object:
Add a new component to the object.
Create a Spring Data value for the properties that can change (pos, rot, scale).
Keeping a private Handle value; This value is the bridge between the component and the Motion Manager.
Here is what the code would look like by following those steps:
// Component place on the 'A' GameObject.
//This variable is used to control how this object's translation will look.
[SerializeField]
private SpringData translation;
//The bridge value that connects this component to the Motion Manager.
private Handle handler;
//Start can be used, but Awake is better for most cases.
private void Awake(){
//Use Subscribe in order for the Motion Manager to keep track of this object.
handle = MotionManager.Subscribe(transform, translationData);
}
The object can receive forces as inputs, and its position will change; here's what a force to move the object up might look like:
private void Update {
//Use Translate to move the object. (Value isn't exactly what is passed)
handle.Translate(Vector3.up);
}
Why subscribe an object to the manager in the first place?
Subscribing the object to the Motion Manager gives the developer access to the Handle, which is then used to produce procedural motion effects.
We had the system work this way to keep track of the current springs in a game, which allows the developer to stop any of them, or add more.
Last updated
Was this helpful?