AngularMotion Component

Events

Rotated [Old rotation = {Number}]
When entity has rotated due to angular velocity/acceleration a Rotated event is triggered.
NewRotationDirection [New direction = {-1 | 0 | 1}]
When entity has changed rotational direction due to rotational velocity a NewRotationDirection event is triggered. The event is triggered once, if direction is different from last frame.
MotionChange [Motion property name and old value = { key: String, oldValue: Number }]
When a motion property has changed a MotionChange event is triggered.

Component that allows rotating an entity by applying angular velocity and acceleration. All angular motion values are expressed in degrees per second (e.g. an entity with vrotation of 10 will rotate 10 degrees each second).

Properties

Methods

Back to top

.arotation

A property for accessing/modifying the angular(rotational) acceleration. The acceleration increases the velocity over time, resulting in ever increasing speed.

Example

var ent = Crafty.e("2D, AngularMotion");

var arotation = ent.arotation; // retrieve the angular acceleration
ent.arotation += 1; // increase the angular acceleration
ent.arotation = 0; // reset the angular acceleration
Back to top

.drotation

A number that reflects the change in rotation (difference between the old & new rotation) that was applied in the last frame.

Example

var ent = Crafty.e("2D, AngularMotion");

var drotation = ent.drotation; // the change of rotation in the last frame
Back to top

.vrotation

A property for accessing/modifying the angular(rotational) velocity. The velocity remains constant over time, unless the acceleration increases the velocity.

Example

var ent = Crafty.e("2D, AngularMotion");

var vrotation = ent.vrotation; // retrieve the angular velocity
ent.vrotation += 1; // increase the angular velocity
ent.vrotation = 0; // reset the angular velocity
Back to top

.resetAngularMotion()

public this .resetAngularMotion()

Reset all motion (resets velocity, acceleration, motionDelta).