Difference between revisions of "B2.DistanceJoint:setDampingRatio"
From GiderosMobile
(added example) |
|||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | |||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
− | '''Class:''' [[ | + | '''Class:''' [[b2.DistanceJoint]]<br/> |
=== Description === | === Description === | ||
Line 9: | Line 8: | ||
b2.DistanceJoint:setDampingRatio(ratio) | b2.DistanceJoint:setDampingRatio(ratio) | ||
</source> | </source> | ||
+ | |||
+ | For a rigid distance joint you would set the frequency equals to 0 and the damping equals to 1. | ||
=== Parameters === | === Parameters === | ||
− | '''ratio''': (number) the damping ratio <br/> | + | '''ratio''': (number) the damping ratio (usually between 0 and 1)<br/> |
+ | |||
+ | === Example === | ||
+ | '''This is some code from an actual game ;-)''' | ||
+ | <source lang="lua"> | ||
+ | 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 | ||
+ | </source> | ||
{{B2.DistanceJoint}} | {{B2.DistanceJoint}} |
Revision as of 08:32, 8 January 2022
Available since: Gideros 2011.6
Class: b2.DistanceJoint
Description
Sets the damping ratio of this distance joint. 0 = no damping, 1 = critical damping.
b2.DistanceJoint:setDampingRatio(ratio)
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 ;-)
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