Difference between revisions of "B2.World:createJoint"

From GiderosMobile
Line 4: Line 4:
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.World|b2.World]]<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/b2.World|b2.World]]<br/>
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate><br />
+
<translate>
 
Creates a joint given a definition. All 10 types of joints is created by using this function:<br />
 
Creates a joint given a definition. All 10 types of joints is created by using this function:<br />
 
<br />
 
<br />
<br />
+
===Revolute Joint===
&lt;h3&gt;Revolute Joint&lt;/h3&gt;<br />
 
<br />
 
 
Revolute joint definition. This requires defining an anchor point where the bodies are joined. The definition uses<br />
 
Revolute joint definition. This requires defining an anchor point where the bodies are joined. The definition uses<br />
 
local anchor points so that the initial configuration can violate the constraint slightly. You also need to specify the<br />
 
local anchor points so that the initial configuration can violate the constraint slightly. You also need to specify the<br />
Line 20: Line 18:
 
and recompute the mass, the joints will be broken.<br />
 
and recompute the mass, the joints will be broken.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.REVOLUTE_JOINT<br />
&lt;li&gt;**type**: (number) b2.REVOLUTE_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''referenceAngle''': (number) The bodyB angle minus bodyA angle in the reference state (radians).<br />
&lt;li&gt;**referenceAngle**: (number) The bodyB angle minus bodyA angle in the reference state (radians).&lt;/li&gt;<br />
+
'''enableLimit''': (boolean) A flag to enable joint limits.<br />
&lt;li&gt;**enableLimit**: (boolean) A flag to enable joint limits.&lt;/li&gt;<br />
+
'''lowerAngle''': (number) The lower angle for the joint limit (radians).<br />
&lt;li&gt;**lowerAngle**: (number) The lower angle for the joint limit (radians).&lt;/li&gt;<br />
+
'''upperAngle''': (number) The upper angle for the joint limit (radians).<br />
&lt;li&gt;**upperAngle**: (number) The upper angle for the joint limit (radians).&lt;/li&gt;<br />
+
'''enableMotor''': (boolean) A flag to enable the joint motor.<br />
&lt;li&gt;**enableMotor**: (boolean) A flag to enable the joint motor.&lt;/li&gt;<br />
+
'''motorSpeed''': (number) The desired motor speed. Usually in radians per second.<br />
&lt;li&gt;**motorSpeed**: (number) The desired motor speed. Usually in radians per second.&lt;/li&gt;<br />
+
'''maxMotorTorque''': (number) The maximum motor torque used to achieve the desired motor speed. Usually in N-m.<br />
&lt;li&gt;**maxMotorTorque**: (number) The maximum motor torque used to achieve the desired motor speed. Usually in N-m.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createRevoluteJointDef]] function to create a revolute joint definiton table easier.<br />
 
Also, you can use [[b2.createRevoluteJointDef]] function to create a revolute joint definiton table easier.<br />
 
<br />
 
<br />
<br />
+
===Prismatic Joint===
&lt;h3&gt;Prismatic Joint&lt;/h3&gt;<br />
 
<br />
 
 
Prismatic joint definition. This requires defining a line of motion using an axis and an anchor point. The definition uses<br />
 
Prismatic joint definition. This requires defining a line of motion using an axis and an anchor point. The definition uses<br />
 
local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is<br />
 
local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is<br />
 
zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.<br />
 
zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.PRISMATIC_JOINT<br />
&lt;li&gt;**type**: (number) b2.PRISMATIC_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''localAxisA''': (table) The local translation axis in bodyA.<br />
&lt;li&gt;**localAxisA**: (table) The local translation axis in bodyA.&lt;/li&gt;<br />
+
'''referenceAngle''': (number) The body2 angle minus body1 angle in the reference state (radians).<br />
&lt;li&gt;**referenceAngle**: (number) The body2 angle minus body1 angle in the reference state (radians).&lt;/li&gt;<br />
+
'''enableLimit''': (boolean) A flag to enable joint limits.<br />
&lt;li&gt;**enableLimit**: (boolean) A flag to enable joint limits.&lt;/li&gt;<br />
+
'''lowerTranslation''': (number) The lower translation limit, usually in meters.<br />
&lt;li&gt;**lowerTranslation**: (number) The lower translation limit, usually in meters.&lt;/li&gt;<br />
+
'''upperTranslation''': (number) The upper translation limit, usually in meters.<br />
&lt;li&gt;**upperTranslation**: (number) The upper translation limit, usually in meters.&lt;/li&gt;<br />
+
'''enableMotor''': (boolean) A flag to enable the joint motor.<br />
&lt;li&gt;**enableMotor**: (boolean) A flag to enable the joint motor.&lt;/li&gt;<br />
+
'''maxMotorForce''': (number) The maximum motor torque, usually in N-m.<br />
&lt;li&gt;**maxMotorForce**: (number) The maximum motor torque, usually in N-m.&lt;/li&gt;<br />
+
'''motorSpeed''': (number) The desired motor speed in radians per second.<br />
&lt;li&gt;**motorSpeed**: (number) The desired motor speed in radians per second.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createPrismaticJointDef]] function to create a prismatic joint definiton table easier.<br />
 
Also, you can use [[b2.createPrismaticJointDef]] function to create a prismatic joint definiton table easier.<br />
 
<br />
 
<br />
<br />
+
===Distance Joint===
&lt;h3&gt;Distance Joint&lt;/h3&gt;<br />
 
<br />
 
 
Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint.<br />
 
Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint.<br />
 
The definition uses local anchor points so that the initial configuration can violate the constraint slightly.<br />
 
The definition uses local anchor points so that the initial configuration can violate the constraint slightly.<br />
 
This helps when saving and loading a game.<br />
 
This helps when saving and loading a game.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.DISTANCE_JOINT<br />
&lt;li&gt;**type**: (number) b2.DISTANCE_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''length''': (number) The natural length between the anchor points. Do not use a zero or short length.<br />
&lt;li&gt;**length**: (number) The natural length between the anchor points. Do not use a zero or short length.&lt;/li&gt;<br />
+
'''frequencyHz''': (number) The mass-spring-damper frequency in Hertz.<br />
&lt;li&gt;**frequencyHz**: (number) The mass-spring-damper frequency in Hertz.&lt;/li&gt;<br />
+
'''dampingRatio''': (number) The damping ratio. 0 = no damping, 1 = critical damping.<br />
&lt;li&gt;**dampingRatio**: (number) The damping ratio. 0 = no damping, 1 = critical damping.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createDistanceJointDef]] function to create a distance joint definiton table easier.<br />
 
Also, you can use [[b2.createDistanceJointDef]] function to create a distance joint definiton table easier.<br />
 
<br />
 
<br />
<br />
+
===Pulley Joint===
&lt;h3&gt;Pulley Joint&lt;/h3&gt;<br />
 
<br />
 
 
Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, max lengths for each side, and a pulley ratio.<br />
 
Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, max lengths for each side, and a pulley ratio.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.PULLEY_JOINT<br />
&lt;li&gt;**type**: (number) b2.PULLEY_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''groundAnchorA''': (table) The first ground anchor in world coordinates. This point never moves.<br />
&lt;li&gt;**groundAnchorA**: (table) The first ground anchor in world coordinates. This point never moves.&lt;/li&gt;<br />
+
'''groundAnchorB''': (table) The second ground anchor in world coordinates. This point never moves.<br />
&lt;li&gt;**groundAnchorB**: (table) The second ground anchor in world coordinates. This point never moves.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''lengthA''': (number) The a reference length for the segment attached to bodyA.<br />
&lt;li&gt;**lengthA**: (number) The a reference length for the segment attached to bodyA.&lt;/li&gt;<br />
+
'''lengthB''': (number) The a reference length for the segment attached to bodyB.<br />
&lt;li&gt;**lengthB**: (number) The a reference length for the segment attached to bodyB.&lt;/li&gt;<br />
+
'''ratio''': (number) The pulley ratio, used to simulate a block-and-tackle.<br />
&lt;li&gt;**ratio**: (number) The pulley ratio, used to simulate a block-and-tackle.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createPulleyJointDef]] function to create a pulley joint definiton table easier.<br />
 
Also, you can use [[b2.createPulleyJointDef]] function to create a pulley joint definiton table easier.<br />
 
<br />
 
<br />
<br />
+
===Mouse Joint===
&lt;h3&gt;Mouse Joint&lt;/h3&gt;<br />
 
<br />
 
 
Mouse joint definition. This requires a world target point, tuning parameters, and the time step.<br />
 
Mouse joint definition. This requires a world target point, tuning parameters, and the time step.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.MOUSE_JOINT<br />
&lt;li&gt;**type**: (number) b2.MOUSE_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''target''': (table) The initial world target point. This is assumed to coincide with the body anchor initially.<br />
&lt;li&gt;**target**: (table) The initial world target point. This is assumed to coincide with the body anchor initially.&lt;/li&gt;<br />
+
'''maxForce''': (number) The maximum constraint force that can be exerted to move the candidate body. Usually you will express as some multiple of the weight (multiplier * mass * gravity).<br />
&lt;li&gt;**maxForce**: (number) The maximum constraint force that can be exerted to move the candidate body. Usually you will express as some multiple of the weight (multiplier * mass * gravity).&lt;/li&gt;<br />
+
'''frequencyHz''': (number) The response speed.<br />
&lt;li&gt;**frequencyHz**: (number) The response speed.&lt;/li&gt;<br />
+
'''dampingRatio''': (number) The damping ratio. 0 = no damping, 1 = critical damping.<br />
&lt;li&gt;**dampingRatio**: (number) The damping ratio. 0 = no damping, 1 = critical damping.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createMouseJointDef]] function to create a mouse joint definiton table easier.<br />
 
Also, you can use [[b2.createMouseJointDef]] function to create a mouse joint definiton table easier.<br />
 
<br />
 
<br />
&lt;h3&gt;Gear Joint&lt;/h3&gt;<br />
+
===Gear Joint===
<br />
 
 
Gear joint definition. This definition requires two existing revolute or prismatic joints (any combination will work). The provided joints<br />
 
Gear joint definition. This definition requires two existing revolute or prismatic joints (any combination will work). The provided joints<br />
 
must attach a dynamic body to a static body.<br />
 
must attach a dynamic body to a static body.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.GEAR_JOINT<br />
&lt;li&gt;**type**: (number) b2.GEAR_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''joint1''': (b2.Joint) The first revolute/prismatic joint attached to the gear joint.<br />
&lt;li&gt;**joint1**: (b2.Joint) The first revolute/prismatic joint attached to the gear joint.&lt;/li&gt;<br />
+
'''joint2''': (b2.Joint) The second revolute/prismatic joint attached to the gear joint.<br />
&lt;li&gt;**joint2**: (b2.Joint) The second revolute/prismatic joint attached to the gear joint.&lt;/li&gt;<br />
+
'''ratio''': (number) The gear ratio.<br />
&lt;li&gt;**ratio**: (number) The gear ratio.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createGearJointDef]] function to create a gear joint definiton table easier.<br />
 
Also, you can use [[b2.createGearJointDef]] function to create a gear joint definiton table easier.<br />
 
<br />
 
<br />
&lt;h3&gt;Wheel Joint&lt;/h3&gt;<br />
+
===Wheel Joint===
<br />
 
 
Wheel joint definition. This requires defining a line of motion using an axis and an anchor point. <br />
 
Wheel joint definition. This requires defining a line of motion using an axis and an anchor point. <br />
 
The definition uses local anchor points and a local axis so that the initial configuration can violate <br />
 
The definition uses local anchor points and a local axis so that the initial configuration can violate <br />
Line 148: Line 124:
 
Using local anchors and a local axis helps when saving and loading a game.<br />
 
Using local anchors and a local axis helps when saving and loading a game.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.WHEEL_JOINT<br />
&lt;li&gt;**type**: (number) b2.WHEEL_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''localAxisA''': (table) The local translation axis in bodyA.<br />
&lt;li&gt;**localAxisA**: (table) The local translation axis in bodyA.&lt;/li&gt;<br />
+
'''enableMotor''': (boolean) A flag to enable the joint motor.<br />
&lt;li&gt;**enableMotor**: (boolean) A flag to enable the joint motor.&lt;/li&gt;<br />
+
'''maxMotorTorque''': (number) The maximum motor torque, usually in N-m.<br />
&lt;li&gt;**maxMotorTorque**: (number) The maximum motor torque, usually in N-m.&lt;/li&gt;<br />
+
'''motorSpeed''': (number) The desired motor speed in radians per second.<br />
&lt;li&gt;**motorSpeed**: (number) The desired motor speed in radians per second.&lt;/li&gt;<br />
+
'''frequencyHz''': (number) Suspension frequency, zero indicates no suspension.<br />
&lt;li&gt;**frequencyHz**: (number) Suspension frequency, zero indicates no suspension.&lt;/li&gt;<br />
+
'''dampingRatio''': (number) Suspension damping ratio, one indicates critical damping.<br />
&lt;li&gt;**dampingRatio**: (number) Suspension damping ratio, one indicates critical damping.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createWheelJointDef]] function to create a wheel joint definiton table easier.<br />
 
Also, you can use [[b2.createWheelJointDef]] function to create a wheel joint definiton table easier.<br />
 
<br />
 
<br />
&lt;h3&gt;Weld Joint&lt;/h3&gt;<br />
+
===Weld Joint===
<br />
 
 
Weld joint definition. You need to specify local anchor points where they are attached and the relative<br />
 
Weld joint definition. You need to specify local anchor points where they are attached and the relative<br />
 
body angle. The position of the anchor points is important for computing the reaction torque.<br />
 
body angle. The position of the anchor points is important for computing the reaction torque.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.WELD_JOINT<br />
&lt;li&gt;**type**: (number) b2.WELD_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''referenceAngle''': (number) The bodyB angle minus bodyA angle in the reference state (radians).<br />
&lt;li&gt;**referenceAngle**: (number) The bodyB angle minus bodyA angle in the reference state (radians).&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createWeldJointDef]] function to create a weld joint definiton table easier.<br />
 
Also, you can use [[b2.createWeldJointDef]] function to create a weld joint definiton table easier.<br />
 
<br />
 
<br />
&lt;h3&gt;Friction Joint&lt;/h3&gt;<br />
+
===Friction Joint===
<br />
 
 
Friction joint definition.<br />
 
Friction joint definition.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.LINE_JOINT<br />
&lt;li&gt;**type**: (number) b2.LINE_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''maxForce''': (number) The maximum friction force in N.<br />
&lt;li&gt;**maxForce**: (number) The maximum friction force in N.&lt;/li&gt;<br />
+
'''maxTorque''': (number) The maximum friction torque in N-m.<br />
&lt;li&gt;**maxTorque**: (number) The maximum friction torque in N-m.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
<br />
 
<br />
 
&lt;h3&gt;Rope Joint&lt;/h3&gt;<br />
 
 
<br />
 
<br />
 +
===Rope Joint===
 
Rope joint definition. This requires two body anchor points and a maximum length.<br />
 
Rope joint definition. This requires two body anchor points and a maximum length.<br />
 
<br />
 
<br />
&lt;ul&gt;<br />
+
'''type''': (number) b2.ROPE_JOINT<br />
&lt;li&gt;**type**: (number) b2.ROPE_JOINT&lt;/li&gt;<br />
+
'''bodyA''': (b2.Body) The first attached body.<br />
&lt;li&gt;**bodyA**: (b2.Body) The first attached body.&lt;/li&gt;<br />
+
'''bodyB''': (b2.Body) The second attached body.<br />
&lt;li&gt;**bodyB**: (b2.Body) The second attached body.&lt;/li&gt;<br />
+
'''collideConnected''': (boolean) Set this flag to true if the attached bodies should collide.<br />
&lt;li&gt;**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.&lt;/li&gt;<br />
+
'''localAnchorA''': (table) The local anchor point relative to bodyA&#039;s origin.<br />
&lt;li&gt;**localAnchorA**: (table) The local anchor point relative to bodyA&#039;s origin.&lt;/li&gt;<br />
+
'''localAnchorB''': (table) The local anchor point relative to bodyB&#039;s origin.<br />
&lt;li&gt;**localAnchorB**: (table) The local anchor point relative to bodyB&#039;s origin.&lt;/li&gt;<br />
+
'''maxLength''': (number) The maximum length of the rope.<br />
&lt;li&gt;**maxLength**: (number) The maximum length of the rope.&lt;/li&gt;<br />
 
&lt;/ul&gt;<br />
 
 
<br />
 
<br />
 
Also, you can use [[b2.createRopeJointDef]] function to create a rope joint definiton table easier.<br />
 
Also, you can use [[b2.createRopeJointDef]] function to create a rope joint definiton table easier.<br />

Revision as of 13:54, 5 October 2018


Available since: Gideros 2011.6
Class: b2.World

Description

Creates a joint given a definition. All 10 types of joints is created by using this function:

Revolute Joint

Revolute joint definition. This requires defining an anchor point where the bodies are joined. The definition uses
local anchor points so that the initial configuration can violate the constraint slightly. You also need to specify the
initial relative angle for joint limits. This helps when saving and loading a game. The local anchor points are measured from
the body's origin rather than the center of mass because:

1. you might not know where the center of mass will be.
2. if you add/remove shapes from a body

and recompute the mass, the joints will be broken.

type: (number) b2.REVOLUTE_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
referenceAngle: (number) The bodyB angle minus bodyA angle in the reference state (radians).
enableLimit: (boolean) A flag to enable joint limits.
lowerAngle: (number) The lower angle for the joint limit (radians).
upperAngle: (number) The upper angle for the joint limit (radians).
enableMotor: (boolean) A flag to enable the joint motor.
motorSpeed: (number) The desired motor speed. Usually in radians per second.
maxMotorTorque: (number) The maximum motor torque used to achieve the desired motor speed. Usually in N-m.

Also, you can use b2.createRevoluteJointDef function to create a revolute joint definiton table easier.

Prismatic Joint

Prismatic joint definition. This requires defining a line of motion using an axis and an anchor point. The definition uses
local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is
zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.

type: (number) b2.PRISMATIC_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
localAxisA: (table) The local translation axis in bodyA.
referenceAngle: (number) The body2 angle minus body1 angle in the reference state (radians).
enableLimit: (boolean) A flag to enable joint limits.
lowerTranslation: (number) The lower translation limit, usually in meters.
upperTranslation: (number) The upper translation limit, usually in meters.
enableMotor: (boolean) A flag to enable the joint motor.
maxMotorForce: (number) The maximum motor torque, usually in N-m.
motorSpeed: (number) The desired motor speed in radians per second.

Also, you can use b2.createPrismaticJointDef function to create a prismatic joint definiton table easier.

Distance Joint

Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint.
The definition uses local anchor points so that the initial configuration can violate the constraint slightly.
This helps when saving and loading a game.

type: (number) b2.DISTANCE_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
length: (number) The natural length between the anchor points. Do not use a zero or short length.
frequencyHz: (number) The mass-spring-damper frequency in Hertz.
dampingRatio: (number) The damping ratio. 0 = no damping, 1 = critical damping.

Also, you can use b2.createDistanceJointDef function to create a distance joint definiton table easier.

Pulley Joint

Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, max lengths for each side, and a pulley ratio.

type: (number) b2.PULLEY_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
groundAnchorA: (table) The first ground anchor in world coordinates. This point never moves.
groundAnchorB: (table) The second ground anchor in world coordinates. This point never moves.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
lengthA: (number) The a reference length for the segment attached to bodyA.
lengthB: (number) The a reference length for the segment attached to bodyB.
ratio: (number) The pulley ratio, used to simulate a block-and-tackle.

Also, you can use b2.createPulleyJointDef function to create a pulley joint definiton table easier.

Mouse Joint

Mouse joint definition. This requires a world target point, tuning parameters, and the time step.

type: (number) b2.MOUSE_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
target: (table) The initial world target point. This is assumed to coincide with the body anchor initially.
maxForce: (number) The maximum constraint force that can be exerted to move the candidate body. Usually you will express as some multiple of the weight (multiplier * mass * gravity).
frequencyHz: (number) The response speed.
dampingRatio: (number) The damping ratio. 0 = no damping, 1 = critical damping.

Also, you can use b2.createMouseJointDef function to create a mouse joint definiton table easier.

Gear Joint

Gear joint definition. This definition requires two existing revolute or prismatic joints (any combination will work). The provided joints
must attach a dynamic body to a static body.

type: (number) b2.GEAR_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
joint1: (b2.Joint) The first revolute/prismatic joint attached to the gear joint.
joint2: (b2.Joint) The second revolute/prismatic joint attached to the gear joint.
ratio: (number) The gear ratio.

Also, you can use b2.createGearJointDef function to create a gear joint definiton table easier.

Wheel Joint

Wheel joint definition. This requires defining a line of motion using an axis and an anchor point.
The definition uses local anchor points and a local axis so that the initial configuration can violate
the constraint slightly. The joint translation is zero when the local anchor points coincide in world space.
Using local anchors and a local axis helps when saving and loading a game.

type: (number) b2.WHEEL_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
localAxisA: (table) The local translation axis in bodyA.
enableMotor: (boolean) A flag to enable the joint motor.
maxMotorTorque: (number) The maximum motor torque, usually in N-m.
motorSpeed: (number) The desired motor speed in radians per second.
frequencyHz: (number) Suspension frequency, zero indicates no suspension.
dampingRatio: (number) Suspension damping ratio, one indicates critical damping.

Also, you can use b2.createWheelJointDef function to create a wheel joint definiton table easier.

Weld Joint

Weld joint definition. You need to specify local anchor points where they are attached and the relative
body angle. The position of the anchor points is important for computing the reaction torque.

type: (number) b2.WELD_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
referenceAngle: (number) The bodyB angle minus bodyA angle in the reference state (radians).

Also, you can use b2.createWeldJointDef function to create a weld joint definiton table easier.

Friction Joint

Friction joint definition.

type: (number) b2.LINE_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
maxForce: (number) The maximum friction force in N.
maxTorque: (number) The maximum friction torque in N-m.

Rope Joint

Rope joint definition. This requires two body anchor points and a maximum length.

type: (number) b2.ROPE_JOINT
bodyA: (b2.Body) The first attached body.
bodyB: (b2.Body) The second attached body.
collideConnected: (boolean) Set this flag to true if the attached bodies should collide.
localAnchorA: (table) The local anchor point relative to bodyA's origin.
localAnchorB: (table) The local anchor point relative to bodyB's origin.
maxLength: (number) The maximum length of the rope.

Also, you can use b2.createRopeJointDef function to create a rope joint definiton table easier.

(b2.Joint) = b2.World:createJoint(jointDef)

Parameters

jointDef: (table)

Return values

Returns (b2.Joint) created joint