gravitate(strength, scale, source_id, paths) gravitate.messages = [] = []


Simulates an attracting (or repulsing) force that accelerates the element towards another target element or towards a path made of one or several move() controllers. Acceleration is proportional to the inverse square of the distance to the target.

Note that since the algorithm is not precise (that's not the point of behave3d), this controller tends to accelerate the element more and more when passing close to the target even if it's not moving. This over-acceleration can be tampered with the use of the slow() controller.

The physics simulation applies one translate transform.


Visit page Controller # Common Parameters for documentation on the parameters, common to all controllers: id, paused and disabled.

Parameters of gravitate():

Strength of force. Larger value results in faster acceleration. Note that negative values are posible, which will make the force repulsing instead of attracting. Default value: 1
A scaling factor for the distance to the target. Lower values cause the distance to be smaller for the sake of calculations, resulting in stronger force. However, due to the non-linear force/distance relation, setting a lower value for scale is not the same as setting a larger strength value. Set lower values of scale when you want more linear response, i.e. the force not to weaken so quickly with distance. Default value: 0.1
DOM ID of the target element to which the force attracts if no paths are specified. Default value: ""
A space-delimited list of controller ids of move() controllers belonging to this element. The sum of these controllers' current coordinates makes the coordinates of the "source of gravity". Default value: ""

Accepted Messages

Visit page Controller # Common Messages for documentation on the messages, accepted by all controllers: pause, unpause, enable, disable, params and remove.

Messages specific to gravitate(): none

Generated Events

Visit page Controller # Common Events for documentation on the events, generated by all controllers: frame, remove, paused, unpaused enabled and disabled.

Events specific to gravitate(): none

Interaction with DOM

Changes Log

  1. Controller introduced in v.0.80

See Also