This translation is community contributed and may not be up to date. We only maintain the English version of the documentation. Read this manual in English
Defold は 2D 物理シミュレーションでジョイント(joint)をサポートしています。ジョイントは、何らかの拘束(constraint)を使って2つのコリジョンオブジェクト(collision object)を接続します。サポートされているジョイントの種類は次のとおりです。
bodyB 上の点を bodyA 上の直線に拘束します。ホイールジョイントにはサスペンション用のばねもあります。Box2D ではホイールジョイント(Wheel joint)と呼ばれます。現在、ジョイントは physics.create_joint() を使ってプログラムからのみ作成できます。
エディターでのジョイント作成のサポートは予定されていますが、リリース日は決まっていません。
-- connect two collision objects with a fixed joint constraint (rope)
physics.create_joint(physics.JOINT_TYPE_FIXED, "obj_a#collisionobject", "my_test_joint", vmath.vector3(10, 0, 0), "obj_b#collisionobject", vmath.vector3(0, 20, 0), { max_length = 20 })
上記のコードは、2つのコリジョンオブジェクト obj_a#collisionobject と obj_b#collisionobject の間に、ID が my_test_joint の固定ジョイントを作成します。ジョイントは、コリジョンオブジェクト obj_a#collisionobject の中心から右に10ピクセルの位置と、コリジョンオブジェクト obj_b#collisionobject の中心から上に20ピクセルの位置に接続されます。ジョイントの最大長は20ピクセルです。
ジョイントは physics.destroy_joint() を使って破棄できます。
-- destroy a joint previously connected to the first collision object
physics.destroy_joint("obj_a#collisionobject", "my_test_joint")
ジョイントのプロパティは、physics.get_joint_properties() を使って読み取り、physics.set_joint_properties() を使って設定できます。
function update(self, dt)
if self.accelerating then
local hinge_props = physics.get_joint_properties("obj_a#collisionobject", "my_hinge")
-- increase motor speed by 100 revolutions per second
hinge_props.motor_speed = hinge_props.motor_speed + 100 * 2 * math.pi * dt
physics.set_joint_properties("obj_a#collisionobject", "my_hinge", hinge_props)
end
end
ジョイントに加わる反力とトルクは、physics.get_joint_reaction_force() と physics.get_joint_reaction_torque() を使って読み取れます。