This article's documentation is for anything that uses the Source engine. Click here for more information.

Phys constraint: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
(example vmf)
 
(19 intermediate revisions by 13 users not shown)
Line 1: Line 1:
A constraint that keeps the relative position and orientation of two objects fixed.
{{tabs|main=source|source=1|source2=1|phys_constraint}}
__NOTOC__
{{CD|CPhysFixed|file1=physconstraint.cpp}}
{{this is a|point entity|name=phys_constraint}}
It forces one entity to keep its position in relation to another. The two objects need not be touching, or even near to each other.
 
If a phys_constraint is attached to a func_train, it will not hold. Instead, parent a func_brush to the train and attach the phys_constraint to that.
{{Official vmf example|sdk_phys_ballsocket.vmf}}


==Keyvalues==
==Keyvalues==
*{{kv targetname}}
{{KV TwoObjectPhysics}}
*'''attach1''' <target_destination>
sdk_phys_ballsocket.vmf
:One of the entities to constrain
*'''attach2''' <target_destination>
:The other entity to constrain
*'''constraintsystem''' <target_destination>
:The name of a [[phys_constraintsystem]] that this constraint should be a part of. All constraints on a set of entities should be placed in the same system, or they will fight each other during simulation.
*'''forcelimit''' <float>
:The amount of force an impact must apply to the constraint to break it. Measured in pounds. A way of calculating this is to set it to the mass of an object that would break this constraint if it were resting on the constrainted objects.
*'''torquelimit''' <float>
:The amount of torque required to break the constraint. Measured in pounds*distance (pounds*inches). A way of calculating this is to multiply any reference mass by the resting distance (from the center of mass of the object) needed to break the constraint.
*'''breaksound''' <sound>
:A sound played when the constraint is broken.
 
==Flags==
==Flags==
*1: No Collision until break
{{Fl TwoObjectPhysics}}
*2: ''not used''
*4: Start inactive
*8: Change mass to keep stable attachment to world


==Inputs==
==Inputs==
*{{i targetname}}
{{I TwoObjectPhysics}}
*'''Break'''
:Force the constraint to break.
*'''TurnOn'''
:Enable the constraint.  Do this when the objects don't exist when the constraint spawns, or when you have deactivated the constraint.  Broken constraints can ''not'' be turned on.  They have been deleted.
*'''TurnOff'''
:Disable this constraint.


==Outputs==
==Outputs==
*{{o targetname}}
{{O TwoObjectPhysics}}
*'''OnBreak'''
:Fired when the constraint breaks.


==See also==
[[Category:Constraints|C]]
*[[phys_lengthconstraint]] to keep the distance fixed but not the orientation

Latest revision as of 05:55, 29 April 2025

C++ Class hierarchy
CPhysFixed
CPhysConstraint
CLogicalEntity
CServerOnlyEntity
CBaseEntity
C++ physconstraint.cpp

phys_constraint is a point entity available in all Source Source games. It forces one entity to keep its position in relation to another. The two objects need not be touching, or even near to each other.

If a phys_constraint is attached to a func_train, it will not hold. Instead, parent a func_brush to the train and attach the phys_constraint to that.

PlacementTip.pngExample:See steamapps/common/sourcesdk_content/hl2/mapsrc/sdk_phys_ballsocket.vmf for example use (comes with Source SDK installation [confirm])

Keyvalues

TwoObjectPhysics:

Entity 1 (attach1) <targetname>
Entity 2 (attach2) <targetname>
The entities to constrain. Leave one or the other field blank to constrain to the world.
Note.pngNote:Only one entity will be constrained, even if several share the given targetname.
Constraint System Manager (constraintsystem) <targetname>
A phys_constraintsystem that this constraint should be a part of. This avoids the "jiggling" caused by constraints applied to the same set of entities fighting with each other.
Force Limit to Break (forcelimit) <float>
Impact force required to break the constraint, in pounds. 0 means infinite. A way of calculating this is to set it to the weight of an object that would break the constraint if it were resting on its objects.
Torque Limit to Break (torquelimit) <float>
Torque required to break the constraint, in pounds*inches. 0 means infinite. A way of calculating this is to multiply any reference mass by the resting distance (from the center of mass of the object) needed to break the constraint.
Play Sound on Break (breaksound) <string>
A sound played when the constraint is broken.
Follow teleport distance (teleportfollowdistance) <float>
If one constrained object teleports more than this many units away, the other will teleport with it.

sdk_phys_ballsocket.vmf

Flags

No Collision until break : [1]
Start inactive : [4]
Change mass to keep stable attachment to world : [8]
Do not connect entities until turned on : [16]

Inputs

TwoObjectPhysics:
Break
Force the constraint to break.
TurnOn
Enable the constraint; do this if the constrained objects don't exist when it spawns. Note that broken constraints cannot be turned back on as they have been deleted.
TurnOff
Disable the constraint.

Outputs

TwoObjectPhysics:
OnBreak
Fired when the constraint breaks.