Joints: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>NXTBoy
Things I don't remember and can't check are in HTML comments. This might need merging into another page.
>Samacado
changed stuff to code examples, added and changed links - note that you can do (link name|link) text in double brackets
Line 1: Line 1:
A '''joint''', called a "connection" while a game is loading, is something that connects two parts together. Common types of joints are [[Weld]]s, [[Snap]]s, and [[Hinge]]s. Joints are represented using a [[JointInstance]] object, which has four important properties: C0, C1, Part0, and Part1.
A '''joint''', called a "connection" while a game is loading, is something that connects two parts together. Common types of joints are [[Weld]]s, [[Snap]]s, and [[Hinge|Hinges]]. Joints are represented using a [[JointInstance]] object, which has four important properties: [[C0]], [[C1]], [[Part0]], and [[Part1]].


== Automatic creation ==
== Automatic creation ==
Line 8: Line 8:
=== Fixed Joints ===
=== Fixed Joints ===
Joints have a conceptual origin coordinate frame, to which both parts are attached.  
Joints have a conceptual origin coordinate frame, to which both parts are attached.  
 
<code lua>
jointOrigin == joint.Part0.CFrame * joint.C0 == joint.Part1.CFrame * joint.C1
jointOrigin == joint.Part0.CFrame * joint.C0 == joint.Part1.CFrame * joint.C1
 
</code>
In the case of fixed joints, this origin position is not important. <!--Or do explosions only act on joint origins? -->
In the case of fixed joints, this origin position is not important. <!--Or do explosions only act on joint origins? -->


It is sufficient to make the origin position the center of Part1, and C1 the identity CFrame. For example:
It is sufficient to make the origin position the center of Part1, and C1 the identity CFrame. For example:
 
<code lua>
local cf = ... --The transformation from A to B
local cf = ... --The transformation from A to B
   
   
local weld = Instance.new("Weld")
local weld = Instance.new("Weld")
      weld.Part0 = workspace.A
      weld.Part0 = workspace.A
      weld.Part1 = workspace.B
      weld.Part1 = workspace.B
      weld.C0 = cf
      weld.C0 = cf
      weld.C1 = CFrame.new(0,0,0)
      weld.C1 = CFrame.new(0,0,0)
 
</code>
Will ensure that workspace.A * cf == workspace.B
Will ensure that <code lua>workspace.A * cf == workspace.B</code>


=== Rotating Joints ===
=== Rotating Joints ===

Revision as of 17:54, 15 January 2012

A joint, called a "connection" while a game is loading, is something that connects two parts together. Common types of joints are Welds, Snaps, and Hinges. Joints are represented using a JointInstance object, which has four important properties: C0, C1, Part0, and Part1.

Automatic creation

Advanced

Fixed Joints

Joints have a conceptual origin coordinate frame, to which both parts are attached. jointOrigin == joint.Part0.CFrame * joint.C0 == joint.Part1.CFrame * joint.C1 In the case of fixed joints, this origin position is not important.

It is sufficient to make the origin position the center of Part1, and C1 the identity CFrame. For example: local cf = ... --The transformation from A to B

local weld = Instance.new("Weld")

     weld.Part0 = workspace.A
     weld.Part1 = workspace.B
     weld.C0 = cf
     weld.C1 = CFrame.new(0,0,0)

Will ensure that workspace.A * cf == workspace.B

Rotating Joints

In a rotating joint, the conceptual origin is important. This dictates the position, and in some cases, the axis around which the joint rotates.