Skip to main content

Constraint

Constraints keep two points together in place and maintain uniform distance between the two. Constraints and Points together join to keep a RigidBody in place hence making both Points and Constraints a vital part of the library. Custom constraints such as Ropes, Rods, Bridges and chains can also be made. Points of two rigid bodies can be connected with constraints, two individual points can also be connected with constraints to form Ropes etc.

NOTE:

Constraints are handled by the Engine by default. Constraints are created for RigidBodies on creation. This class should only be used to create custom constraints.

Use Engine:Create() to create custom constraints!

Types

type Canvas = {
topLeft: Vector2,
size: Vector2,
frame: Frame
}

type SegmentConfig = {
restLength: number?,
render: boolean,
thickness: number,
support: boolean
}

Functions

Constraint.new()

This method is used to initialize a constraint.

  • parameters - type: string, p1: Point, p2: Point, canvas: Canvas, config: SegmentConfig
  • returns - Constraint

Constraint:Constrain()

NOTE:

This method is automatically handled by the engine!

This method is used to keep uniform distance between the constraint's points, i.e. constrain.

  • parameters - none
  • returns - nil

Constraint:Render()

NOTE:

This method is automatically handled by the engine!

This method is used to update the position and appearance of the constraint on screen.

  • parameters - none
  • returns - nil

Constraint:SetLength()

Used to set the minimum constrained distance between two points. By default, the initial distance between the two points.

  • parameters - newLength: number
  • returns - nil

Constraint:SetSpringConstant()

This method is used to update the Spring constant (by default 0.1) used for spring constraint calculations.

  • parameters - k: number
  • returns - nil

Constraint:Stroke()

This method is used to change the color of a constraint. By default a constraint's color is set to the default value of (WHITE) Color3.new(1, 1, 1).

  • parameters - color: Color3
  • returns - nil

Constraint:Destroy()

Destroys the constraint's GuiObject, destroys the constraint's parent rigid body (if any), destroys its points (point1 and point2), and the constraint is no longer a part of the engine.

  • parameters - none
  • returns - nil

Fetch Methods

Constraint:GetPoints()

Returns the constraints points.

  • parameters - none
  • returns - point1: Point, point2: Point

Constraint:GetFrame()

Returns the UI element for the constrained IF rendered.

  • parameters - none
  • returns - frame: Frame

Constraint:GetLength()

This method returns the current distance between the two points of a constraint.

  • parameters - none
  • returns - distance: number

Constraint:GetId()

The constraints's unique ID can be fetched using this method.

  • parameters - none
  • returns - id: string

Constraint:GetParent()

Returns the Parent (RigidBody) of the Constraint if any.

  • parameters - none
  • return - parent: RigidBody | nil

Properties

Type string (must-have)

It refers to the kind of constraint. It can be Spring, Rod or Rope.

Point1 Point (must-have)

Refers to one of the points connected by the constraint.

Point2 Point (must-have)

Refers to one of the points connected by the constraint.

Visible boolean

Whether or not the constraint is visible/being rendered on screen.

Thickness number

The thickness of the constraint. Size.Y of the constraint's frame.

RestLength number

The minimum or maximum constrained distance between two points.

SpringConstant number

The k (spring) constant marking the stiffness of the constraint.

Color Color3

The BackgroundColor or ImageColor of the constraint's frame.