Difference between revisions of "B2.DistanceJoint:setFrequency"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Sets the mass-spring-damper frequency in Hertz, that is the speed of oscillation also known as the harmonic motion.
 
Sets the mass-spring-damper frequency in Hertz, that is the speed of oscillation also known as the harmonic motion.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
b2.DistanceJoint:setFrequency(frequency)
 
b2.DistanceJoint:setFrequency(frequency)
 
</source>
 
</source>
Line 16: Line 16:
 
=== Example ===
 
=== Example ===
 
'''This is some code from an actual game ;-)'''
 
'''This is some code from an actual game ;-)'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
self.body.ground = self.world:createBody({})
 
self.body.ground = self.world:createBody({})
 
if g_currentlevel == 1 then
 
if g_currentlevel == 1 then

Revision as of 16:35, 12 July 2023

Available since: Gideros 2011.6
Class: b2.DistanceJoint

Description

Sets the mass-spring-damper frequency in Hertz, that is the speed of oscillation also known as the harmonic motion. <syntaxhighlight lang="lua"> b2.DistanceJoint:setFrequency(frequency) </source>

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

Parameters

frequency: (number) the mass-spring-damper frequency in Hertz (usually between 1 and 5)

Example

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




LiquidFun