Difference between revisions of "B2.DistanceJoint:setFrequency"

From GiderosMobile
(added some meat)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[Special:MyLanguage/b2.DistanceJoint|b2.DistanceJoint]]<br/>
+
'''Class:''' [[b2.DistanceJoint]]<br/>
  
 
=== Description ===
 
=== Description ===
Sets the mass-spring-damper frequency in Hertz.
+
Sets the mass-spring-damper frequency in Hertz, that is the speed of oscillation also known as the harmonic motion.
 
<source lang="lua">
 
<source lang="lua">
 
b2.DistanceJoint:setFrequency(frequency)
 
b2.DistanceJoint:setFrequency(frequency)
Line 11: Line 10:
  
 
=== Parameters ===
 
=== Parameters ===
'''frequency''': (number) the mass-spring-damper frequency in Hertz <br/>
+
'''frequency''': (number) the mass-spring-damper frequency in Hertz (usually between 1 and 5)<br/>
 +
 
 +
=== Example ===
 +
'''This is some code from an actual game ;-)'''
 +
<source 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>
  
 
{{B2.DistanceJoint}}
 
{{B2.DistanceJoint}}

Revision as of 08:42, 8 January 2022

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.

b2.DistanceJoint:setFrequency(frequency)

Parameters

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

Example

This is some code from an actual game ;-)

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




LiquidFun