Difference between revisions of "B2.createDistanceJointDef"
From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | |||
'''Available since:''' Gideros 2011.6<br/> | '''Available since:''' Gideros 2011.6<br/> | ||
− | '''Class:''' [[ | + | '''Class:''' [[b2]]<br/> |
=== Description === | === Description === | ||
Line 8: | Line 7: | ||
(Please refer to [[b2.World:createJoint]] function for more information about all the information needed to create a distance joint). | (Please refer to [[b2.World:createJoint]] function for more information about all the information needed to create a distance joint). | ||
− | < | + | <syntaxhighlight lang="lua"> |
(table) = b2.createDistanceJointDef(bodyA,bodyB,anchorAx,anchorAy,anchorBx,anchorBy) | (table) = b2.createDistanceJointDef(bodyA,bodyB,anchorAx,anchorAy,anchorBx,anchorBy) | ||
− | </ | + | </syntaxhighlight> |
=== Parameters === | === Parameters === | ||
− | '''bodyA''': (b2.Body) the first attached body <br/> | + | '''bodyA''': (b2.Body) the first attached body<br/> |
− | '''bodyB''': (b2.Body) the second attached body <br/> | + | '''bodyB''': (b2.Body) the second attached body<br/> |
− | '''anchorAx''': (number) the x coordinate of the world anchor point of bodyA <br/> | + | '''anchorAx''': (number) the x coordinate of the world anchor point of bodyA<br/> |
− | '''anchorAy''': (number) the y coordinate of the world anchor point of bodyA <br/> | + | '''anchorAy''': (number) the y coordinate of the world anchor point of bodyA<br/> |
− | '''anchorBx''': (number) the x coordinate of the world anchor point of bodyB <br/> | + | '''anchorBx''': (number) the x coordinate of the world anchor point of bodyB<br/> |
− | '''anchorBy''': (number) the y coordinate of the world anchor point of bodyB <br/> | + | '''anchorBy''': (number) the y coordinate of the world anchor point of bodyB<br/> |
=== Return values === | === Return values === | ||
− | '''Returns''' (table) | + | '''Returns''' (table) a new distance joint definition table<br/> |
− | === | + | === Example === |
− | < | + | <syntaxhighlight lang="lua"> |
local jointDef = b2.createDistanceJointDef(body1, body2, 100, 100, 200, 100) | local jointDef = b2.createDistanceJointDef(body1, body2, 100, 100, 200, 100) | ||
local distanceJoint = world:createJoint(jointDef) | local distanceJoint = world:createJoint(jointDef) | ||
− | --by default length between two bodies is the length they have between them when joint was created but it is | + | --by default length between two bodies is the length they have between them when joint was created but it is possible to change it using: |
distanceJoint:setLength(200) | distanceJoint:setLength(200) | ||
distanceJoint:setDampingRatio(0.5) | distanceJoint:setDampingRatio(0.5) | ||
distanceJoint:setFrequency(4) | distanceJoint:setFrequency(4) | ||
− | </ | + | </syntaxhighlight> |
{{B2}} | {{B2}} |
Latest revision as of 14:26, 13 July 2023
Available since: Gideros 2011.6
Class: b2
Description
Creates and returns a distance joint definition table with the bodies, anchors, and length using the world anchors.
(Please refer to b2.World:createJoint function for more information about all the information needed to create a distance joint).
(table) = b2.createDistanceJointDef(bodyA,bodyB,anchorAx,anchorAy,anchorBx,anchorBy)
Parameters
bodyA: (b2.Body) the first attached body
bodyB: (b2.Body) the second attached body
anchorAx: (number) the x coordinate of the world anchor point of bodyA
anchorAy: (number) the y coordinate of the world anchor point of bodyA
anchorBx: (number) the x coordinate of the world anchor point of bodyB
anchorBy: (number) the y coordinate of the world anchor point of bodyB
Return values
Returns (table) a new distance joint definition table
Example
local jointDef = b2.createDistanceJointDef(body1, body2, 100, 100, 200, 100)
local distanceJoint = world:createJoint(jointDef)
--by default length between two bodies is the length they have between them when joint was created but it is possible to change it using:
distanceJoint:setLength(200)
distanceJoint:setDampingRatio(0.5)
distanceJoint:setFrequency(4)