Contents

linearGravityField(withVector:)

Creates a field node that accelerates physics bodies in a specific direction.

Declaration

class func linearGravityField(withVector direction: vector_float3) -> SKFieldNode

Parameters

  • direction:

    The direction and magnitude of the gravitational force. The values represent the acceleration of the field in meters per second squared. For example, to simulate earth’s gravity, specify (0, -9.8, 0). The z component on the vector is ignored.

Return Value

A new linear gravity field node.

Discussion

If the field node is rotated, the direction of its gravity field is also rotated. The calculated force is proportional to the physics body’s mass (meaning that the acceleration applied to all affected physics bodies is a constant).

See Also

Creating Field Nodes