Garry's Mod Wiki

constraint

The constraint library allows you to control the constraint system built into the physics engine (rope, weld, ballsockets, etc).

Methods

constraint.AddConstraintTable( Entity ent1, Entity constrt, Entity ent2 = nil, Entity ent3 = nil, Entity ent4 = nil )
This is used internally - although you're able to use it you probably shouldn't. Stores information about constraints in an entity's table.
constraint.AddConstraintTableNoDelete( Entity ent1, Entity constrt, Entity ent2 = nil, Entity ent3 = nil, Entity ent4 = nil )
This is used internally - although you're able to use it you probably shouldn't. Stores info about the constraints on the entity's table. The only difference between this and constraint. AddConstraintTable is that the constraint does not get deleted when the entity is removed.
Entity constraint.AdvBallsocket( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2 = nil, number forceLimit = 0, number torqueLimit = 0, number xMin, number yMin, number zMin, number xMax, number yMax, number zMax, number xFric = 0, number yFric = 0, number zFric = 0, number onlyRotation = 0, number noCollide = 0 )
Creates an advanced ballsocket (ragdoll) constraint. See constraint. Ballsocket for the simpler version.
Entity constraint.Axis( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number forceLimit = 0, number torqueLimit = 0, number friction = 0, number noCollide = 0, Vector localAxis = nil, boolean dontAddTable = false )
Creates an axis constraint.
Entity constraint.Ballsocket( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos, number forcelimit = 0, number torquelimit = 0, number nocollide = 0 )
Creates a ballsocket joint. See See constraint. AdvBallsocket if you also wish to limit rotation angles in some way.
boolean constraint.CanConstrain( Entity ent, number bone )
Basic checks to make sure that the specified entity and bone are valid. Returns false if we should not be constraining the entity.
Entity constraint.CreateKeyframeRope( Vector pos, number width, string material = nil, Entity constraint = nil, Entity ent1, Vector localPos1, number bone1, Entity ent2, Vector localPos2, number bone2, table keyValues = nil )
Creates a rope without any constraint.
Creates an invisible, non-moveable anchor point in the world to which things can be attached. The entity used internally by this function (gmod_anchor) only exists in Sandbox derived gamemodes, meaning this function will only work in these gamemodes. To use this in other gamemodes, you may need to create your own gmod_anchor entity.
Entity, Entity constraint.Elastic( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number constant, number damping, number relDamping, string material = "", number width, boolean stretchOnly = false, table color = color_white )
Creates an elastic rope constraint.
Entity constraint.Find( Entity ent1, Entity ent2, string type, number bone1, number bone2 )
Returns the constraint of a specified type between two entities, if it exists
table constraint.FindConstraint( Entity ent, string type )
Returns the first constraint of a specific type directly connected to the entity found
Entity constraint.FindConstraintEntity( Entity ent, string type )
Returns the other entity involved in the first constraint of a specific type directly connected to the entity
table constraint.FindConstraints( Entity ent, string type )
Returns a table of all constraints of a specific type directly connected to the entity. If you are looking for a list of all constraints, use constraint. GetTable.
constraint.ForgetConstraints( Entity ent )
Make this entity forget any constraints it knows about. Note that this will not actually remove the constraints.
table constraint.GetAllConstrainedEntities( Entity ent, table resultTable = nil )
Returns a table of all entities recursively constrained to an entitiy.
table constraint.GetTable( Entity ent )
Returns a table of all constraints directly connected to the entity. If you are looking for a list of specific constraint(s), use constraint. FindConstraints.
boolean constraint.HasConstraints( Entity ent )
Returns true if the entity has constraints attached to it
Entity, Entity, Entity, Entity constraint.Hydraulic( Player player, Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number length1, number length2, number width, number key, number slider, number speed, string material = "", boolean toggle = true, table color = color_white )
Creates a controllable constraint. Elastic, aka a Hydraulic constraint.
Entity constraint.Keepupright( Entity ent, Angle ang, number bone, number angularLimit )
Creates a keep upright constraint.
Entity, Entity constraint.Motor( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number friction, number torque, number forcetime, number nocollide = 0, number toggle = false, Player player = NULL, number forcelimit = 0, number key_fwd = nil, number key_bwd = nil, number direction = 1, Vector localAxis = nil )
Creates a motor constraint, a player controllable constraint. Axis.
Entity, Entity, Entity, Entity constraint.Muscle( Player player, Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number length1, number length2, number width, number key, number fixed, number period, number amplitude, boolean startOn = false, string material = "", table color = color_white )
Creates a muscle constraint. Very similar to constraint. Hydraulic, but instead of a toggle between fully expanded and contracted, it will continuously alternate between the 2 states while enabled.
Entity constraint.NoCollide( Entity ent1, Entity ent2, number bone1, number bone2 )
Creates an no-collide "constraint". Disables collision between two entities. Does not work with players.
Entity, Entity, Entity, Entity constraint.Pulley( Entity ent1, Entity ent4, number bone1, number bone4, Vector localPos1, Vector localPos4, Vector worldPos2, Vector worldPos3, number forceLimit, boolean rigid = false, number width, string material = "", table color = color_white )
Creates a pulley constraint. It consists of 3 rope segments, 2 of which have variable length, visually connected by a 3rd. Reducing length of one end will increase the length of the other end. You can visualize the pulley like so WPos2 --- WPos3 | | | | Ent1 Ent4
boolean, number constraint.RemoveAll( Entity ent )
Attempts to remove all constraints associated with an entity
boolean, number constraint.RemoveConstraints( Entity ent, string type )
Attempts to remove all constraints of a specified type associated with an entity
Entity, Entity constraint.Rope( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number length, number addLength = 0, number forceLimit = 0, number width, string material = "", boolean rigid = false, table color = color_white )
Creates a simple rope (length) based constraint.
Entity, Entity constraint.Slider( Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number width, string material = "", table color = color_white )
Creates a slider constraint. A slider is like a rope, but allows the constrained object to move only in 1 direction.
Entity constraint.Weld( Entity ent1, Entity ent2, number bone1, number bone2, number forceLimit = 0, boolean noCollide = false, boolean deleteEnt1OnBreak = false )
Creates a weld constraint.
Entity, Entity, Entity constraint.Winch( Player player, Entity ent1, Entity ent2, number bone1, number bone2, Vector localPos1, Vector localPos2, number width, number fwdBind, number bwdBind, number fwdSpeed, number bwdSpeed, string material = "", boolean toggle = false, table color = color_white )
Creates a winch constraint, a player controllable constraint. Elastic, allowing gradually increasing or decreasing the length.