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 物理 このボディを別のボディまたはワールドに 1 点で留め、自由に回転させます。扉、鎖、車輪に使います。
Physics2DSettings 物理 2D 物理ワールドの重力とステップレートです。
PolygonCollider2D 物理 角が最大 8 つのコライダーです。へこんだ輪郭は埋められ、形は常に凸になります。
Rigidbody2D 物理 重力、力、衝突でオブジェクトを動かします。

機能フラグ

ビルドから外せる部分です。define を持つ機能はその define で切り替わり、それ以外はコンポーネントと一緒に取り除かれます。

機能 define デフォルト
Physics 2D DEKI_FEATURE_PHYSICS_2D オン

コンポーネントリファレンス

BoxCollider2D

箱型のコライダーです。

インスペクターでの名前: ボックスコライダー 2D · カテゴリ: 物理 · 型: DekiPhysics2D::BoxCollider2D

プロパティ 型 デフォルト 説明
width float 1 オブジェクトのスケールを掛ける前の幅 (メートル) です。
height float 1 オブジェクトのスケールを掛ける前の高さ (メートル) です。

offsetX, offsetY, friction, bounciness, isTrigger, layer, mask を Collider2D から継承します。

CapsuleCollider2D

直線の辺と丸い両端を持つコライダーです。小さな段差を滑って越えるので、キャラクターに向いています。

インスペクターでの名前: カプセルコライダー 2D · カテゴリ: 物理 · 型: DekiPhysics2D::CapsuleCollider2D

プロパティ 型 デフォルト 制約 説明
radius float 0.25 オブジェクトのスケールを掛ける前の、丸い両端の半径 (メートル) です。
height float 1 オブジェクトのスケールを掛ける前の、端から端までの長さ (メートル) です。
direction enum "Vertical" Vertical, Horizontal 向きです。

offsetX, offsetY, friction, bounciness, isTrigger, layer, mask を Collider2D から継承します。

CircleCollider2D

円形のコライダーです。

インスペクターでの名前: サークルコライダー 2D · カテゴリ: 物理 · 型: DekiPhysics2D::CircleCollider2D

プロパティ 型 デフォルト 説明
radius float 0.5 オブジェクトのスケールを掛ける前の半径 (メートル) です。

offsetX, offsetY, friction, bounciness, isTrigger, layer, mask を Collider2D から継承します。

DistanceJoint2D

このボディ上の点を、別のボディまたはワールドから一定の距離に保ちます。棒やロープに使います。

インスペクターでの名前: ディスタンスジョイント 2D · カテゴリ: 物理 · 型: DekiPhysics2D::DistanceJoint2D

プロパティ 型 デフォルト 説明
connectedAnchorX float 0 接続先のオブジェクト上でつなぐ位置の、中心からの横方向の距離 (メートル) です。接続先のボディがないときはワールド上の点です。
connectedAnchorY float 0 接続先のオブジェクト上でつなぐ位置の、中心からの上方向の距離 (メートル) です。接続先のボディがないときはワールド上の点です。
length float 0 保つ距離 (メートル) です。0 のときは最初の距離になります。
rope bool false ロープにすると、それ以上離れはしませんが、近づくことはできます。

connectedBody, anchorX, anchorY, collideConnected を Joint2D から継承します。

HingeJoint2D

このボディを別のボディまたはワールドに 1 点で留め、自由に回転させます。扉、鎖、車輪に使います。

インスペクターでの名前: ヒンジジョイント 2D · カテゴリ: 物理 · 型: DekiPhysics2D::HingeJoint2D

プロパティ 型 デフォルト 制約 説明
useLimits bool false 下の 2 つの角度を越えて回らないようにします。
lowerAngle float -45 useLimits が許すときに表示 開始位置から時計回りに回れる角度 (度) を負の値で指定します。
upperAngle float 45 useLimits が許すときに表示 開始位置から反時計回りに回れる角度 (度) です。
useMotor bool false トルクが許す範囲で、決まった速さで回転させます。
motorSpeed float 90 useMotor が許すときに表示 1 秒あたりの角度 (度) です。反時計回りです。
maxMotorTorque float 10 useMotor が許すときに表示 モーターが出せる最大のトルク (ニュートンメートル) です。

connectedBody, anchorX, anchorY, collideConnected を Joint2D から継承します。

Physics2DSettings

2D 物理ワールドの重力とステップレートです。

インスペクターでの名前: 2D 物理設定 · カテゴリ: 物理 · 型: DekiPhysics2D::Physics2DSettings

プロパティ 型 デフォルト 制約 説明
gravityX float 0 横方向の重力 (メートル毎秒毎秒) です。
gravityY float -9.81 重力 (メートル毎秒毎秒) です。負の値で下に引きます。
stepsPerSecond int32 60 10 から 240 1 秒あたりの物理ステップ数です。ゲームはどのフレームレートでも同じように動きます。ステップが少ないほど処理が軽くなり、ボードではそれが効いてきます。
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 が許すときに表示

offsetX, offsetY, friction, bounciness, isTrigger, layer, mask を Collider2D から継承します。

Rigidbody2D

重力、力、衝突でオブジェクトを動かします。

インスペクターでの名前: リジッドボディ 2D · カテゴリ: 物理 · 型: DekiPhysics2D::Rigidbody2D

プロパティ 型 デフォルト 制約 説明
type enum "Dynamic" Static, Kinematic, Dynamic ダイナミック: 物理で動きます。キネマティック: コードから速度で動かし、ダイナミックなボディを押しますが、押されることはありません。スタティック: まったく動きません。
mass float 1 押しにくさ (キログラム) です。
gravityScale float 1 このボディにかかる重力の倍率です。0 で浮き、2 で 2 倍の強さで落ちます。
linearDamping float 0 空気や水の中を動くように、毎秒失う速さの割合です。
angularDamping float 0 毎秒失う回転の割合です。
freezeRotation bool false 何がぶつかっても回転しません。プレイヤーを直立させておけます。ボードでは処理が少し軽くなります。
canSleep bool true 静止したらシミュレーションを止めてもよいようにします。力がかかっていなくてもスクリプトで動かし続ける必要があるものはオフにしてください。
continuousCollision bool true 1 ステップで飛び越えてしまうようなものにも止められるようにします。処理時間がかかるのは速く動いている間だけです。

変更履歴

変更履歴は英語です。

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)。プロパティ名はシーンファイルで使われるキーです。名前を変えても別名が残ります (互換性)。