Handle

Description

The Handle is a class that acts as the Spring System for an object, meaning that it takes forces and then moves, rotates and scales the object you create it for; we give its value when subscribing an object to the Motion Manager and can be used to add forces to the object.

To subscribe an object to the Motion Manager, we have to invoke the subscribe method, and pass a Spring Data value for each property we want to change (position, rotation or scale).

If you wish to know more about subscribing objects, you can check out the Motion Manager.

How does it work?

The way this component works is by taking forces we apply to it, and then add them together with the Spring Data values for the correct property, finally it applies the results to the correct game-object. The Handle itself does not have an update method, and thus the Motion Manager is in-charge of invoking all the handles’ updates.

To give you more control over how the forces you apply affect the object, we use the Spring Data class, this class will allow you to change how different forces you apply affect the object.

Usage

Once you subscribe an object to the Motion Manager trough a component, that component gains access to a Handle, this can now be used to translate, rotate or even scale the object in question.

You can move an object every frame by using the following code:

private void Update() {
    //Keeps the spring stretching by one unit.
    handle.Translate(Vector3.up);
}

The final position of the object in this case will not be one unit on the Y axis, as the spring is pulling it towards the rest position, thus the outcome will vary based on the settings used.

Last updated

Was this helpful?