Langsung ke konten
Skillpedia
Pemrograman umum6.6k Β· #13849

unity-physics

Fungsinya

Skill ini menjelaskan cara membuat objek 3D di Unity bergerak, bertabrakan, dan saling mendeteksi dengan memakai mesin fisika bawaan. Skill ini ditujukan untuk developer yang membangun game dengan objek fisik.

Kapan dipakai

  • βœ“Saat Anda memerlukan objek yang bergerak dengan gaya, gravitasi, atau kecepatan di Unity.
  • βœ“Saat Anda ingin kode bereaksi ketika objek bertabrakan atau masuk ke area trigger.
  • βœ“Saat Anda ingin hanya objek tertentu yang bertabrakan satu sama lain, atau memerlukan pemeriksaan ray untuk tanah atau garis pandang.

Link skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-physics/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-physics/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBuat bola saya menggelinding di bawah bukit di Unity dan berhenti saat menabrak dinding.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill menjelaskan cara komponen Rigidbody dan collider bekerja bersama, cara memperbarui fisika dalam fungsi langkah tetap, bagaimana trigger berbeda dari tabrakan, serta bagaimana layer memilih apa yang boleh bertabrakan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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 β†’ PhysicsMaterial is 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 + Collider components.

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

  1. Add a Rigidbody to anything that should be simulated; add a Collider to 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.
  2. Do all physics in FixedUpdate. Read input in Update, store intent, then apply forces / set linearVelocity / call MovePosition in FixedUpdate.
  3. Move bodies through the physics API, not the Transform. Use AddForce, linearVelocity, or MovePosition β€” never assign transform.position to a non-kinematic Rigidbody (it teleports and breaks collision resolution).
  4. Pick collision vs trigger. A solid collision blocks and calls OnCollisionEnter; a Collider with Is Trigger checked passes through and calls OnTriggerEnter.
  5. 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.
  6. 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
Pertanyaan umum

Apa itu Rigidbody?

Rigidbody adalah komponen yang membuat objek mengikuti fisika, seperti gravitasi dan tabrakan.

Apa perbedaan trigger dan tabrakan?

Trigger mendeteksi ketika objek masuk tanpa menghentikannya, sedangkan tabrakan menghentikan objek secara fisik.

Apakah ini mencakup fisika 2D?

Tidak. Fisika 2D memakai komponen yang berbeda, sehingga berada di luar skill ini.

Detail

Deskripsi asli dari pembuat

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.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularitas

Bintang GitHub
6.6k
Peringkat
#13849
Lisensi
Apache-2.0
Diperbarui
28/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa