unity-physics
できること
組み込みの物理エンジンを使い、Unityで3Dのオブジェクトを動かし、衝突させ、互いを検出させる方法を説明します。物理的なオブジェクトを使うゲームを作る開発者向けです。
使う場面
- ✓Unityで、重力、力、速度によってオブジェクトを動かす必要があるとき。
- ✓オブジェクトが衝突したり、トリガーの領域に入ったりしたときに、コードを反応させたいとき。
- ✓特定のオブジェクトだけが衝突するようにしたい、または地面や視線のためにレイでの確認が必要なとき。
スキルのリンク
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-physics/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Unityでボールを坂道で転がし、壁にぶつかったら止まるようにしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
スキルは、Rigidbodyとコライダーのコンポーネントがどのように一緒に働くか、固定ステップの関数で物理を更新する方法、トリガーと衝突の違い、そしてレイヤーがどのオブジェクトの衝突を決めるかを説明します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Unity Physics (Rigidbody / PhysX)
Make objects move, collide, and detect each other with Unity 6.3 LTS's built-in 3D physics
(PhysX). Get the FixedUpdate discipline, trigger-vs-collision rules, and collision layers
right. Targets Unity 6.3 LTS (6000.3).
Unity 6 renames:
Rigidbody.velocity→linearVelocity,drag→linearDamping,angularDrag→angularDamping. The old names still compile in 6.3 LTS but are obsolete (warnings; the API Updater offers the rename), so write the new names.PhysicMaterial→PhysicsMaterialis a hard compile error in old code.
When to use
- Use when giving an object physical motion (forces, velocity, gravity), responding to collisions or triggers, setting up collision layers/masks, raycasting for ground checks or line-of-sight, or connecting bodies with joints.
- Use when scenes/prefabs contain
Rigidbody+Collidercomponents.
When not to use: 2D physics (Rigidbody2D, Collider2D) is a separate API — adapt the
concepts but the types differ. Unity 6.3 also has a separate low-level 2D API
(UnityEngine.LowLevelPhysics2D: PhysicsWorld, PhysicsBody) with its own isolated worlds;
it is not the Rigidbody2D system. Cross-engine feel tuning (timestep, jitter, tunnelling) →
physics-tuning. Reading input that drives movement → unity-input-system.
Core workflow
- Add a
Rigidbodyto anything that should be simulated; add aColliderto anything that should be hit.OnCollision*messages need a Collider on both and at least one dynamic (non-kinematic) Rigidbody: with the default Contact Pairs Mode, kinematic vs kinematic and kinematic vs static send no collision messages. - Do all physics in
FixedUpdate. Read input inUpdate, store intent, then apply forces / setlinearVelocity/ callMovePositioninFixedUpdate. - Move bodies through the physics API, not the Transform. Use
AddForce,linearVelocity, orMovePosition— never assigntransform.positionto a non-kinematic Rigidbody (it teleports and breaks collision resolution). - Pick collision vs trigger. A solid collision blocks and calls
OnCollisionEnter; aColliderwithIs Triggerchecked passes through and callsOnTriggerEnter. - Organise interactions with layers. Put objects on layers and edit the Layer Collision Matrix (Project Settings → Physics) so unrelated things don't test against each other.
- Verify with the Physics Debugger (Window → Analysis → Physics Debugger) and by watching for jitter; if fast objects pass through walls, raise Collision Detection mode.
Patterns
1. Force-based movement in FixedUpdate (with a speed clamp)
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class Mover : MonoBehaviour
{
[SerializeField] private float accel = 30f, maxSpeed = 8f;
private Rigidbody _rb;
private Vector3 _input; // set from Update / input system
private void Awake() => _rb = GetComponent<Rigidbody>();
private void FixedUpdate()
{
_rb.AddForce(_input * accel, ForceMode.Acceleration); // mass-independent accel
// Unity 6.3 LTS: linearVelocity (was 'velocity'). Clamp horizontal speed.
Vector3 flat = new(_rb.linearVelocity.x, 0, _rb.linearVelocity.z);
if (flat.magnitude > maxSpeed)
{
flat = flat.normalized * maxSpeed;
_rb.linearVelocity = new Vector3(flat.x, _rb.linearVelocity.y, flat.z);
}
}
}
ForceMode: Force (continuous, mass-scaled), Acceleration (continuous, ignores mass),
Impulse (instant, mass-scaled — jumps), VelocityChange (instant, ignores mass).
2. Collision vs trigger callbacks
// Solid hit: both have colliders, at least one has a dynamic (non-kinematic) Rigidbody.
private void OnCollisionEnter(Collision col)
{
// GetContact avoids the garbage that the col.contacts array allocates.
Debug.Log($"Hit {col.gameObject.name} at {col.GetContact(0).point}");
}
// Overlap: one collider has 'Is Trigger' = true, and at least one party has a Rigidbody
// (or a Rigidbody carries the trigger). Two static colliders never report.
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Pickup")) Destroy(other.gameObject);
}
3. Ground check with a layer-masked raycast
[SerializeField] private LayerMask groundMask; // set to your "Ground" layer in the Inspector
よくある質問
Rigidbodyとは何ですか?
重力や衝突などの物理に従うオブジェクトにするコンポーネントです。
トリガーと衝突の違いは何ですか?
トリガーはオブジェクトが入ったことを検出しますが、それを遮りません。衝突は物理的にオブジェクトを止めます。
2Dの物理も扱いますか?
いいえ。2Dの物理は別のコンポーネントを使うため、このスキルの範囲外です。
詳細
作者による元の説明
Set up 3D physics in Unity 6.3 LTS: Rigidbody movement and forces, colliders, triggers vs collisions, layer-based collision, raycasts, and joints. Use when adding a Rigidbody, handling OnCollisionEnter/OnTriggerEnter, tuning collision layers, casting rays, or when the user mentions Unity physics, AddForce, isKinematic, or linearVelocity.
人気
- GitHubのスター
- 6.6k
- ランキング
- #13849
- ライセンス
- Apache-2.0
- 更新日
- 2026/10/28
コメント
- …
このリポジトリの他のスキル
router
6.6kエージェントが、エンジンとタスクの種類を見分けて、依頼に合ったゲーム開発のスキルを選べるよう支援します。
ai-behavior-trees-utility-ai
6.6kエージェントが、優先度と点数によって行動を選ぶ、ゲームの敵やキャラクター向けのビヘイビアツリーとユーティリティAIのシステムを作れるよう支援します。
audio-design
6.6kエージェントが、オーディオバス、デシベルでの音量、会話中の音の抑え込み(ダッキング)、適応型の音楽、効果音のバリエーションなど、ゲームのサウンドのミキシングを教えます。
camera-systems
6.6kエージェントが、なめらかに追従し、レベルの内側に収まり、3Dで周回したり見回したりできるゲームのカメラを作れるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。