constraint.Motor

From GMod Wiki

Jump to: navigation, search
Function
Syntax

constraint.Motor( Entity Ent1,

Entity Ent2, Number Bone1, Number Bone2, Vector LPos1, Vector LPos2, Number friction, Number torque, Number forcetime, Number nocollide, Number toggle, Player pl, Number forcelimit, Number numpadkey_fwd, Number numpadkey_bwd )
Where is this used?
Description:
Creates a motor constraint.
Returns: Entity constraint, Entity axis
Part of Library: constraint
Realm: NewerServer.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Constraint.Motor]Constraint.Motor [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionTaken from the Motor tool in toolgun.
Used onNewerServer.png
Code
 
// Get client's CVars
local torque		= self:GetClientNumber( "torque" )
local friction 		= self:GetClientNumber( "friction" )
local nocollide		= self:GetClientNumber( "nocollide" )
local time			= self:GetClientNumber( "forcetime" )
local forekey		= self:GetClientNumber( "fwd" )
local backkey		= self:GetClientNumber( "bwd" )
local toggle		= self:GetClientNumber( "toggle" )
local limit			= self:GetClientNumber( "forcelimit" )
 
local Ent1,  Ent2  = self:GetEnt(1),	 self:GetEnt(2)
local Bone1, Bone2 = self:GetBone(1),	 self:GetBone(2)
local WPos1, WPos2 = self:GetPos(1),	 self:GetPos(2)
local LPos1, LPos2 = self:GetLocalPos(1),self:GetLocalPos(2)
local Norm1, Norm2 = self:GetNormal(1),	 self:GetNormal(2)
local Phys1, Phys2 = self:GetPhys(1), self:GetPhys(2)
 
// Note: To keep stuff ragdoll friendly try to treat things as physics objects rather than entities
local Ang1, Ang2 = Norm1:Angle(), (Norm2 * -1):Angle()
local TargetAngle = Phys1:AlignAngles( Ang1, Ang2 )
 
Phys1:SetAngle( TargetAngle )
 
// Move the object so that the hitpos on our object is at the second hitpos
local TargetPos = WPos2 + (Phys1:GetPos() - self:GetPos(1))
 
// Offset slightly so it can rotate
TargetPos = TargetPos + (2*Norm2)
 
// Set the position
Phys1:SetPos( TargetPos )
 
// Wake up the physics object so that the entity updates
Phys1:Wake()
 
// Set the hinge Axis perpendicular to the trace hit surface
LPos1 = Phys1:WorldToLocal( WPos2 + Norm2 * 64 )
 
local constraint, axis = constraint.Motor( Ent1, Ent2, Bone1, Bone2, LPos1, LPos2, friction, torque, time, nocollide, toggle, self:GetOwner(), limit, forekey, backkey, 1 )
 
 
OutputN/A

Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox