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는 서로 다른 API를 통해 2D와 3D 물리 모두에서 조인트를 지원합니다.
이 매뉴얼은 physics 모듈에서 제공하는 2D 조인트를 설명합니다. Defold 1.13.2부터 3D 프로젝트에서는 bullet3d.constraint를 통해 힌지, 슬라이더, 스프링 등의 제약 조건을 만들고 제어할 수 있습니다. bullet3d.get_rigid_body()로 얻은 강체와 함께 해당 API를 사용하세요.
2D physics API에서 지원하는 조인트 타입은 다음과 같습니다:
bodyB의 한 점을 bodyA의 한 선에 제한합니다. 휠 조인트는 서스펜션 스프링도 제공합니다. Box2D에서는 Wheel joint라고 합니다.여기에서 설명하는 2D 조인트는 physics.create_joint()를 사용해 프로그래밍 방식으로만 만들 수 있습니다:
에디터에서 조인트를 만드는 기능은 계획되어 있지만, 릴리스 날짜는 아직 정해지지 않았습니다.
-- 두 충돌 오브젝트를 고정 조인트 제약 조건(로프)으로 연결합니다
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 })
위 코드는 두 충돌 오브젝트 obj_a#collisionobject와 obj_b#collisionobject 사이에 연결된 id my_test_joint의 고정 조인트를 만듭니다. 이 조인트는 충돌 오브젝트 obj_a#collisionobject 중심에서 오른쪽으로 10픽셀, 충돌 오브젝트 obj_b#collisionobject 중심에서 위로 20픽셀 떨어진 위치에 연결됩니다. 조인트의 최대 길이는 20픽셀입니다.
physics.destroy_joint()를 사용해 조인트를 삭제할 수 있습니다:
-- 이전에 첫 번째 충돌 오브젝트에 연결된 조인트를 삭제합니다
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")
-- 모터 속도를 초당 100회전만큼 증가시킵니다
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()로 읽을 수 있습니다.