Difference between revisions of "B2.DistanceJoint:setDampingRatio"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[b2.DistanceJoint]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.DistanceJoint|b2.DistanceJoint]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate><br />
+
Sets the damping ratio of this distance joint. 0 = no damping, 1 = critical damping.
Sets the damping ratio of this distance joint. 0 = no damping, 1 = critical damping. <br />
+
<syntaxhighlight lang="lua">
<br /></translate>
+
b2.DistanceJoint:setDampingRatio(ratio)
<source lang="lua">
+
</syntaxhighlight>
b2.DistanceJoint:setDampingRatio(ratio)
+
 
</source>
+
For a rigid distance joint you would set the frequency equals to 0 and the damping equals to 1.
=== <translate>Parameters</translate> ===
+
 
'''ratio''': (number) <translate>the damping ratio</translate> <br/>
+
=== Parameters ===
 +
'''ratio''': (number) the damping ratio (usually between 0 and 1)<br/>
 +
 
 +
=== Example ===
 +
'''This is some code from an actual game ;-)'''
 +
<syntaxhighlight 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>
 +
 
 +
{{B2.DistanceJoint}}

Latest revision as of 17:14, 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.

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 ;-)

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




LiquidFun