Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Spring

A spring, connecting two bodies.

example
const spring = new Spring(boxBody, sphereBody, {
restLength: 0,
stiffness: 50,
damping: 1,
})

// Compute the force after each step
world.addEventListener('postStep', (event) => {
spring.applyForce()
})

Hierarchy

  • Spring

Index

Constructors

constructor

  • new Spring(bodyA: Body, bodyB: Body, options?: { damping?: number; localAnchorA?: Vec3; localAnchorB?: Vec3; restLength?: number; stiffness?: number; worldAnchorA?: Vec3; worldAnchorB?: Vec3 }): Spring
  • Parameters

    • bodyA: Body
    • bodyB: Body
    • options: { damping?: number; localAnchorA?: Vec3; localAnchorB?: Vec3; restLength?: number; stiffness?: number; worldAnchorA?: Vec3; worldAnchorB?: Vec3 } = {}
      • Optional damping?: number

        Damping of the spring. A number >= 0.

        default

        1

      • Optional localAnchorA?: Vec3

        Anchor for bodyA in local bodyA coordinates. Where to hook the spring to body A, in local body coordinates.

        default

        new Vec3()

      • Optional localAnchorB?: Vec3

        Anchor for bodyB in local bodyB coordinates. Where to hook the spring to body B, in local body coordinates.

        default

        new Vec3()

      • Optional restLength?: number

        Rest length of the spring. A number > 0.

        default

        1

      • Optional stiffness?: number

        Stiffness of the spring. A number >= 0.

        default

        100

      • Optional worldAnchorA?: Vec3

        Where to hook the spring to body A, in world coordinates.

      • Optional worldAnchorB?: Vec3

        Where to hook the spring to body B, in world coordinates.

    Returns Spring

Properties

bodyA

bodyA: Body

First connected body.

bodyB

bodyB: Body

Second connected body.

damping

damping: number

Damping of the spring. A number >= 0.

default

1

localAnchorA

localAnchorA: Vec3

Anchor for bodyA in local bodyA coordinates. Where to hook the spring to body A, in local body coordinates.

default

new Vec3()

localAnchorB

localAnchorB: Vec3

Anchor for bodyB in local bodyB coordinates. Where to hook the spring to body B, in local body coordinates.

default

new Vec3()

restLength

restLength: number

Rest length of the spring. A number > 0.

default

1

stiffness

stiffness: number

Stiffness of the spring. A number >= 0.

default

100

Methods

applyForce

  • applyForce(): void

getWorldAnchorA

  • getWorldAnchorA(result: Vec3): void
  • Get the anchor point on body A, in world coordinates.

    Parameters

    • result: Vec3

      The vector to store the result in.

    Returns void

getWorldAnchorB

  • getWorldAnchorB(result: Vec3): void
  • Get the anchor point on body B, in world coordinates.

    Parameters

    • result: Vec3

      The vector to store the result in.

    Returns void

setWorldAnchorA

  • setWorldAnchorA(worldAnchorA: Vec3): void
  • Set the anchor point on body A, using world coordinates.

    Parameters

    Returns void

setWorldAnchorB

  • setWorldAnchorB(worldAnchorB: Vec3): void
  • Set the anchor point on body B, using world coordinates.

    Parameters

    Returns void