DEKI/ENGINE 문서
매뉴얼 API 참조
deki-physics-2d 0.40.1
Deki 패키지 레퍼런스
deki-physics-2d

2D 물리: 강체, 상자·원·캡슐·다각형 콜라이더, 트리거, 레이캐스트, 경첩과 밧줄. 고정 스텝으로 돌기 때문에 게임은 어떤 프레임 레이트에서도 똑같이 움직입니다.

저장소: github.com/dekiengine/deki-physics-2d · 최신 릴리스: 0.40.0 · 엔진 0.40.0 이상 필요

DekiEditor --packages-add deki-physics-2d <project> 또는 패키지 관리자로 설치합니다. 엔진 자체의 컴포넌트와 C++ API는 Deki 문서에 있습니다.

에디터에는 Physics 2D(으)로 표시됩니다.

컴포넌트

컴포넌트 카테고리 설명
BoxCollider2D 물리 상자 모양 콜라이더입니다.
CapsuleCollider2D 물리 옆면이 곧고 양 끝이 둥근 콜라이더입니다. 작은 턱을 미끄러지듯 넘어가므로 캐릭터에 잘 맞습니다.
CircleCollider2D 물리 원 모양 콜라이더입니다.
DistanceJoint2D 물리 이 바디의 한 점을 다른 바디나 월드로부터 정해진 거리에 유지합니다. 막대와 로프에 씁니다.
HingeJoint2D 물리 이 바디를 다른 바디나 월드의 한 점에 고정하고 자유롭게 회전하게 합니다. 문, 사슬, 바퀴에 씁니다.
Physics2DSettings 물리 2D 물리 월드의 중력과 스텝 속도입니다.
PolygonCollider2D 물리 꼭짓점이 최대 8개인 콜라이더입니다. 움푹 들어간 윤곽은 메워지므로 모양은 항상 볼록합니다.
Rigidbody2D 물리 중력, 힘, 충돌로 오브젝트를 움직입니다.

기능 플래그

빌드에서 뺄 수 있는 부분입니다. define이 있는 기능은 그 define으로 켜고 끄며, 나머지는 컴포넌트와 함께 제거됩니다.

기능 define 기본값
Physics 2D DEKI_FEATURE_PHYSICS_2D 켜짐

컴포넌트 레퍼런스

BoxCollider2D

상자 모양 콜라이더입니다.

인스펙터 이름: 박스 콜라이더 2D · 카테고리: 물리 · 유형: DekiPhysics2D::BoxCollider2D

속성 유형 기본값 설명
width float 1 너비(미터)이며, 오브젝트의 스케일을 적용하기 전 값입니다.
height float 1 높이(미터)이며, 오브젝트의 스케일을 적용하기 전 값입니다.

Collider2D에서 offsetX, offsetY, friction, bounciness, isTrigger, layer, mask을(를) 상속합니다.

CapsuleCollider2D

옆면이 곧고 양 끝이 둥근 콜라이더입니다. 작은 턱을 미끄러지듯 넘어가므로 캐릭터에 잘 맞습니다.

인스펙터 이름: 캡슐 콜라이더 2D · 카테고리: 물리 · 유형: DekiPhysics2D::CapsuleCollider2D

속성 유형 기본값 제약 설명
radius float 0.25 둥근 끝의 반지름(미터)이며, 오브젝트의 스케일을 적용하기 전 값입니다.
height float 1 끝에서 끝까지의 길이(미터)이며, 오브젝트의 스케일을 적용하기 전 값입니다.
direction enum "Vertical" Vertical, Horizontal 놓인 방향입니다.

Collider2D에서 offsetX, offsetY, friction, bounciness, isTrigger, layer, mask을(를) 상속합니다.

CircleCollider2D

원 모양 콜라이더입니다.

인스펙터 이름: 원형 콜라이더 2D · 카테고리: 물리 · 유형: DekiPhysics2D::CircleCollider2D

속성 유형 기본값 설명
radius float 0.5 반지름(미터)이며, 오브젝트의 스케일을 적용하기 전 값입니다.

Collider2D에서 offsetX, offsetY, friction, bounciness, isTrigger, layer, mask을(를) 상속합니다.

DistanceJoint2D

이 바디의 한 점을 다른 바디나 월드로부터 정해진 거리에 유지합니다. 막대와 로프에 씁니다.

인스펙터 이름: 거리 조인트 2D · 카테고리: 물리 · 유형: DekiPhysics2D::DistanceJoint2D

속성 유형 기본값 설명
connectedAnchorX float 0 연결된 오브젝트에서 연결되는 위치로, 중심에서 옆으로 떨어진 거리(미터)입니다. 연결된 바디가 없으면 월드의 한 점입니다.
connectedAnchorY float 0 연결된 오브젝트에서 연결되는 위치로, 중심에서 위로 떨어진 거리(미터)입니다. 연결된 바디가 없으면 월드의 한 점입니다.
length float 0 유지할 거리(미터)입니다. 0: 시작할 때 떨어져 있는 거리.
rope bool false 로프는 더 멀어지지는 못하게 하지만 가까워지는 것은 허용합니다.

Joint2D에서 connectedBody, anchorX, anchorY, collideConnected을(를) 상속합니다.

HingeJoint2D

이 바디를 다른 바디나 월드의 한 점에 고정하고 자유롭게 회전하게 합니다. 문, 사슬, 바퀴에 씁니다.

인스펙터 이름: 힌지 조인트 2D · 카테고리: 물리 · 유형: DekiPhysics2D::HingeJoint2D

속성 유형 기본값 제약 설명
useLimits bool false 아래의 두 각도를 넘어 돌지 않게 합니다.
lowerAngle float -45 useLimits이(가) 허용할 때 표시 시작 위치에서 시계 방향으로 돌 수 있는 각도(도)로, 음수로 지정합니다.
upperAngle float 45 useLimits이(가) 허용할 때 표시 시작 위치에서 시계 반대 방향으로 돌 수 있는 각도(도)입니다.
useMotor bool false 토크가 허용하는 한 정해진 속도로 회전시킵니다.
motorSpeed float 90 useMotor이(가) 허용할 때 표시 초당 각도(도)이며, 시계 반대 방향입니다.
maxMotorTorque float 10 useMotor이(가) 허용할 때 표시 모터가 낼 수 있는 최대 토크(뉴턴미터)입니다.

Joint2D에서 connectedBody, anchorX, anchorY, collideConnected을(를) 상속합니다.

Physics2DSettings

2D 물리 월드의 중력과 스텝 속도입니다.

인스펙터 이름: 2D 물리 설정 · 카테고리: 물리 · 유형: DekiPhysics2D::Physics2DSettings

속성 유형 기본값 제약 설명
gravityX float 0 옆 방향 중력(미터/초²)입니다.
gravityY float -9.81 중력(미터/초²)입니다. 음수면 아래로 당깁니다.
stepsPerSecond int32 60 10~240 초당 물리 스텝 수입니다. 게임은 어떤 프레임 레이트에서도 똑같이 동작합니다. 스텝이 적을수록 비용이 줄어들며, 보드에서는 이것이 중요합니다.
allowSleep bool true 멈춘 바디는 무언가가 닿을 때까지 시뮬레이션하지 않습니다. 큰 씬에서 시간을 아끼고, 쌓인 것들이 가만히 있게 합니다.

PolygonCollider2D

꼭짓점이 최대 8개인 콜라이더입니다. 움푹 들어간 윤곽은 메워지므로 모양은 항상 볼록합니다.

인스펙터 이름: 폴리곤 콜라이더 2D · 카테고리: 물리 · 유형: DekiPhysics2D::PolygonCollider2D

속성 유형 기본값 제약 설명
pointCount int32 3 3~8 꼭짓점 개수입니다.
point0 Vector2 [-0.5, -0.5]
point1 Vector2 [0.5, -0.5]
point2 Vector2 [0.0, 0.5]
point3 Vector2 [0.0, 0.0] pointCount이(가) 허용할 때 표시
point4 Vector2 [0.0, 0.0] pointCount이(가) 허용할 때 표시
point5 Vector2 [0.0, 0.0] pointCount이(가) 허용할 때 표시
point6 Vector2 [0.0, 0.0] pointCount이(가) 허용할 때 표시
point7 Vector2 [0.0, 0.0] pointCount이(가) 허용할 때 표시

Collider2D에서 offsetX, offsetY, friction, bounciness, isTrigger, layer, mask을(를) 상속합니다.

Rigidbody2D

중력, 힘, 충돌로 오브젝트를 움직입니다.

인스펙터 이름: 리지드바디 2D · 카테고리: 물리 · 유형: DekiPhysics2D::Rigidbody2D

속성 유형 기본값 제약 설명
type enum "Dynamic" Static, Kinematic, Dynamic 다이내믹: 물리로 움직입니다. 키네마틱: 코드에서 속도로 움직이며, 다이내믹 바디를 밀지만 밀리지는 않습니다. 스태틱: 절대 움직이지 않습니다.
mass float 1 밀기 어려운 정도(킬로그램)입니다.
gravityScale float 1 이 바디에 적용할 중력에 곱합니다. 0이면 떠 있고, 2면 두 배로 세게 떨어집니다.
linearDamping float 0 매초 잃는 속도의 비율로, 공기나 물속을 움직이는 것과 같습니다.
angularDamping float 0 매초 잃는 회전 속도의 비율입니다.
freezeRotation bool false 무엇에 부딪혀도 회전하지 않습니다. 플레이어를 똑바로 서 있게 합니다. 보드에서는 비용이 조금 줄어듭니다.
canSleep bool true 멈추면 시뮬레이션을 멈출 수 있습니다. 힘이 작용하지 않아도 스크립트에서 계속 움직이게 해야 하는 것에는 끄세요.
continuousCollision bool true 한 스텝에 건너뛰어 버릴 것에서도 멈춥니다. 빠르게 움직이는 동안에만 시간이 듭니다.

변경 내역

변경 내역은 영어로 되어 있습니다.

0.40.0

Added

  • The package: rigid bodies that move and turn, box, circle, capsule and convex polygon colliders, triggers, layers, raycasts and collision and trigger callbacks, on a fixed step so a game plays the same at any frame rate.
  • A body falls, balances and spins about the centre of its colliders, wherever its object's origin is.
  • Hinge joints with limits and a motor, and distance joints and ropes.
  • Bodies at rest sleep, with everything touching them, until something wakes them.
  • Fast bodies stop at what they would otherwise jump over in one step.
  • A collider with no Rigidbody 2D follows its object, and a body follows an object that other code moves.
  • Nothing is allocated while a scene runs, once its lists have reached their size.
  • Colliders and joints are drawn in the Scene View, with handles to drag a selected collider's size and corners.
  • A world at rest is not stepped. With no body awake or moving and nothing changed from outside since the last step, a step returns at once; it used to find every contact again and copy what it kept of each. A settled pile of 100 boxes went from 22.7 to 0.2 microseconds a step on a desktop, and ends where it did before, bit for bit. Whatever code changes while the world rests (a push, a body or a trigger removed) is still stepped.
  • A contact keeps its two bodies and the friction between them for the step: each solver pass looked the shapes up again and took a square root.
  • A body asleep, or moved by code and not spinning, is not given its sine and cosine again every step.
  • A contact's two points are solved together. Solved one after the other, a box set down flat rocked from corner to corner, and a stack leant and fell.
  • A bounce gives back the speed the two arrived with, before the step's gravity. A ball that keeps all its speed rose 4% higher with every bounce; it now comes back to where it fell from.
  • A step is solved in sub-steps (World::subSteps, 4): each moves the bodies a little and solves from where they then are, so the weight of the top of a stack reaches the ground within the step. Several passes over one whole step carried it a box a pass, and a stack of more than ten stood or fell by the rounding of a sum: twenty boxes stood on a desktop and fell on an ESP32-S3. Now ten stand however they are set down, twenty with six sub-steps, the same on both.
  • An overlap is pushed out as a spring would, and the speed that takes is taken back in the same sub-step, so it moves the bodies and adds no energy. Bodies rest 2.5 to 5 mm into each other; a stack of 20 went to sleep 16 mm into each box below.
  • Shapes within 5 mm of each other already have a contact, which lets them close the gap and no more. Boxes set down exactly touching had none until they had sunk into each other, a box a step: the top of a stack of 20 fell half a metre. Nothing is reported, and a trigger is not entered, until two shapes overlap.
  • A joint is set up from where its bodies are in each sub-step. A pendulum keeps 97% of its swing over 20 seconds; it kept 90%.
  • A step costs less than it did before sub-steps. On a T-Deck 30 boxes awake take 1.6 ms a step (1.7 before), 10 take 0.35 ms and a chain of 30 hinges 0.8 ms (0.9). A pass works on a contact point as four numbers instead of two arms; a body keeps what its contacts hold it with, so a sub-step does not go over the contacts to start from it; last step's contacts are found through a sorted list of their pairs instead of being sorted themselves; a face the other shape is plainly behind is not measured; and no pass divides, which a processor without a divide instruction does slowly.

이전 릴리스: CHANGELOG.md


패키지의 리플렉션 데이터에서 생성했습니다(엔진 0.40.1). 속성 이름은 씬 파일에서 쓰는 키입니다. 이름을 바꿔도 별칭이 유지됩니다(호환성).