UniversalConstraint

Show Deprecated

A physics constraint that ensures two axes on two rigid bodies remain perpendicular. An example use of this constraint are power transmission between the transmission and rear drive shafts of rear-wheel drive cars, robotics, etc.

The constraint ensures that two attachments are co-located (similar to BallSocketConstraint) and that their secondary axes remain perpendicular (see the picture below). In this sense, this constraint is more restrictive than the BallSocketConstraint but is less restrictive than HingeConstraint (by one degree of freedom).

Example UniversalConstraint

If LimitsEnabled is true, then the relative motion of the primary axis of Attachment1 is limited by a cone. This cone is formed via Attachment0 and its primary axis and makes an angle of MaxAngle with it.

Code Samples

Creating a UniversalConstraint

1local BodyA = Instance.new("Part")
2BodyA.Size = Vector3.new(1, 1, 1)
3BodyA.Position = Vector3.new(2, 10, 1)
4BodyA.CanCollide = false
5BodyA.Anchored = true
6BodyA.Parent = workspace
7
8local BodyB = Instance.new("Part")
9BodyB.Size = Vector3.new(1, 1, 1)
10BodyB.Position = Vector3.new(-2, 10, 1)
11BodyB.CanCollide = false
12BodyB.Parent = workspace
13
14local attachmentA = Instance.new("Attachment")
15attachmentA.Position = Vector3.new(-1, 0, 0)
16attachmentA.Axis = Vector3.new(-1, 0, 0)
17attachmentA.SecondaryAxis = Vector3.new(0, 0, 1)
18attachmentA.Parent = BodyA
19
20local attachmentB = Instance.new("Attachment")
21attachmentB.Position = Vector3.new(1, 0, 0)
22attachmentB.Axis = Vector3.new(-1, 0, 0)
23attachmentB.SecondaryAxis = Vector3.new(0, 1, 0)
24attachmentB.Parent = BodyB
25
26local universalConstraint = Instance.new("UniversalConstraint")
27universalConstraint.Attachment0 = attachmentA
28universalConstraint.Attachment1 = attachmentB
29universalConstraint.Parent = BodyA

Summary

Properties

Determines whether the angular motion of attachments' primary axes is limited.

The max angle, in degrees, of the constraint's limiting cone.

The constraint's visualization radius.

The restitution coefficient of the cone constraint.

Events

Methods

Properties

LimitsEnabled

This property, when enabled, limits the relative angular motion of the primary axes of attachments through a cone constraint. The default value is false.

The example below demonstrates how developers can enable a cone limit on the relative motion of the primary axes:


1universalConstraint.LimitsEnabled = true
2

MaxAngle

This property determines the max angle, in degrees, of the UniversalConstraint's limiting cone. The limiting cone is formed from Attachment0 and its primary axis. The default value is 45.0 degrees.

In order for this property to take affect, the constraint's UniversalConstraint.LimitsEnabled property must be set to true.

For example, the code snippet below sets LimitsEnabled to true and limits the UniversalConstraint.MaxAngle to 10 degrees:


1universalConstraint.LimitsEnabled = true
2universalConstraint.MaxAngle = 10
3

Radius

This property indicates the visualization radius, in studs, of the constraint when the constraint's details are off and the constraint is selected. The default value is 0.2 studs.

Restitution

This property determines the restitution of the two limits, or how elastic they are. The value defaults to 0 and can be any floating number in the range [0, 1].


1This property only applies when `Class.UniversalConstraint.LimitsEnabled` is set to true.
2

The elasticity affects the Attachments connected by the UniversalConstraint when they reach the end of the range specified by UniversalConstraint.MaxAngle.

Events

Methods