Difference between revisions of "B2.DistanceJoint:setDampingRatio"

From GiderosMobile
m (Text replacement - "</source" to "</syntaxhighlight")
Line 7: Line 7:
 
<source lang="lua">
 
<source lang="lua">
 
b2.DistanceJoint:setDampingRatio(ratio)
 
b2.DistanceJoint:setDampingRatio(ratio)
</source>
+
</syntaxhighlight>
  
 
For a rigid distance joint you would set the frequency equals to 0 and the damping equals to 1.
 
For a rigid distance joint you would set the frequency equals to 0 and the damping equals to 1.
Line 25: Line 25:
 
self.body.joint:setFrequency(1.2)
 
self.body.joint:setFrequency(1.2)
 
end
 
end
</source>
+
</syntaxhighlight>
  
 
{{B2.DistanceJoint}}
 
{{B2.DistanceJoint}}

Revision as of 17:46, 12 July 2023

Available since: Gideros 2011.6
Class: b2.DistanceJoint

Description

Sets the damping ratio of this distance joint. 0 = no damping, 1 = critical damping. <source lang="lua"> b2.DistanceJoint:setDampingRatio(ratio) </syntaxhighlight>

For a rigid distance joint you would set the frequency equals to 0 and the damping equals to 1.

Parameters

ratio: (number) the damping ratio (usually between 0 and 1)

Example

This is some code from an actual game ;-) <source lang="lua"> self.body.ground = self.world:createBody({}) if g_currentlevel == 2 then self.body.ground:setPosition(xposx, xposy) local jointDef = b2.createDistanceJointDef(self.body.ground, self.body, xposx + 0, xposy - 64, xposx, xposy) self.body.joint = self.world:createJoint(jointDef) self.body.joint:setDampingRatio(0.5) self.body.joint:setFrequency(1.2) end </syntaxhighlight>




LiquidFun