Log inGet started
Package

components.module

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

ecs.PhysicsJoint

Component spec for ecs.PhysicsJoint, which maps to the native PhysicsJoint, a constraint binding this entity's body to another. connectedEntityId names the other body; the anchors and axis are single Vec3 fields. Each end is the nearest body at or above its entity: an entity under a body (a marker at a beam's end) joins that body at the marker's position and orientation, with its anchor and axis measured in the marker's frame, so a body takes any number of joints, each on an entity of its own. The constructor ecs.PhysicsJoint{...} builds a value the generic ecs verbs apply, and the component is behavior-bearing: ecs.get exposes a motor drive.

Fields

  • jointType: string? — "Fixed" | "Hinge" | "Ball" | "Prismatic" | "Spring".
  • connectedEntityId: string? — the other body to bind to.
  • anchorSelf: { number }? — {x, y, z}.
  • anchorOther: { number }? — {x, y, z}.
  • axis: { number }? — {x, y, z}.
  • breakForce: number?
  • stiffness: number?: a "Spring" joint's spring constant, in newtons per metre; on a "Hinge", "Ball", "Prismatic" or "Generic" joint with no motorMode, a spring pulling each of its axes back to where its frames align. Negative (the default) takes the kind's own: 100 on a spring joint, no spring on every other kind.
  • damping: number?: how strongly that spring resists the speed it moves at. Negative (the default) takes the kind's own: 10 on a spring joint, none on every other kind.
  • restLength: number?: the distance in metres between the anchors a "Spring" joint settles at. Negative (the default) takes their distance when the joint is built; written negative on the live joint, the spring keeps the length it rests at.
  • regionSelf: { [string]: any }?: when this entity is a soft body, the particles the joint is anchored on: { kind, min, max, point, world }, kind "Whole" (the body's frame, the default), "Box" (the particles between min and max) or "Nearest" (the particle nearest point), in the entity's local space or, with world = true, in world space.
  • regionOther: { [string]: any }?: the same for the connected entity, when it is a soft body.
  • built: boolean?: set by the simulation while the solver holds the joint.
  • problem: string?: set by the simulation when it cannot build the joint (an end with no body at or above it, a connected id no entity carries, two ends on one body), naming the entity; empty otherwise.

Handle methods

ecs.get(id, ecs.PhysicsJoint) returns the generic data handle plus this method, bound to the entity's id.

  • setMotor(targetVelocity, maxForce) — drive the joint motor.

Usage

ecs.insert(id, ecs.PhysicsJoint{ jointType = "Hinge", connectedEntityId = otherId, axis = { 0, 1, 0 } })
local joint = ecs.get(id, ecs.PhysicsJoint)
joint:setMotor(2, 50)