Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

unity-physics

БесплатноБез исполняемых скриптовНе проверен

Unity 6.3 LTS physics in 3D and 2D: Rigidbody and Rigidbody2D, forces and linearVelocity, the layer collision matrix and raycasts. Use when an object falls…

gamedev-skillsот gamedev-skills★ 12 656 звёзд на GitHub

Об этом скилле

Unity Physics (3D PhysX and 2D)

Make objects move, collide and detect each other in Unity 6.3 LTS (6000.3). Unity has two separate physics engines: 3D (Rigidbody, Collider, Physics) and 2D (Rigidbody2D, Collider2D, Physics2D). They never interact: a Rigidbody2D falls straight through a BoxCollider, and 3D callbacks never fire on 2D objects.

When to use

  • Giving an object physical motion, responding to collisions or triggers, setting up layers, ray or shape casts for ground checks and line of sight, joints, kinematic movers.
  • The project's scenes or prefabs contain Rigidbody/Collider or Rigidbody2D/Collider2D.

When not to use: cross-engine feel (fixed timestep choice, jitter strategy, tunnelling trade-offs) → physics-tuning; Tilemap Collider 2D and composite merging → unity-tilemap-2d; pathfinding agents → unity-navmesh; reading the input that drives movement → unity-input-system. If Unity's official fix-3d-physics-collisions or create-2d-physics skill is installed and an Editor is connected, it can drive the Editor for scene setup; this skill still owns the API and the code.

Workflow

  1. Find out which engine the object uses before touching code. Grep the scene or prefab YAML for a Rigidbody2D: or Rigidbody: document header (and BoxCollider2D: vs BoxCollider:). Mixed 2D and 3D components on interacting objects are a bug, not a design.
  2. Read the physics settings as text, not through the Inspector. 3D settings live in ProjectSettings/DynamicsManager.asset (m_QueriesHitTriggers, m_ContactPairsMode, m_LayerCollisionMatrix), 2D settings in ProjectSettings/Physics2DSettings.asset (m_QueriesHitTriggers, m_QueriesStartInColliders, m_SimulationMode, m_LayerCollisionMatrix). The matrix is a hex bitfield: read and change it with Physics.GetIgnoreLayerCollision/IgnoreLayerCollision (2D: the Physics2D versions) rather than editing the hex.
  3. Do physics in FixedUpdate. Read input in Update, store intent, apply forces or set linearVelocity or call MovePosition in FixedUpdate. Both engines step after FixedUpdate by default.
  4. Move bodies through the physics API, not the Transform. AddForce, linearVelocity, MovePosition. Writing transform.position on a dynamic body teleports it and skips collision resolution.
  5. Pick collision vs trigger. A solid collider blocks and calls OnCollisionEnter (OnCollisionEnter2D); isTrigger passes through and calls OnTriggerEnter (OnTriggerEnter2D). At least one of the pair needs a rigidbody.
  6. Prune layer pairs that never need to touch. A runtime IgnoreLayerCollision call is not saved; for a lasting change ask the user to untick the pair in Project Settings > Physics (or Physics 2D) > Layer Collision Matrix. The Unity CLI's settings.physics set does not cover the matrix (it sets gravity, solver iterations and bounce threshold only).
  7. Verify with one of the checks below, then remove any temporary logging.

Patterns

1. Force-based movement in FixedUpdate with a speed clamp (3D)

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
        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 and Acceleration are continuous (mass-scaled vs not); Impulse and VelocityChange are instant (mass-scaled vs not; use them for jumps).

2. Ground check that ignores triggers (3D)

[SerializeField] private LayerMask groundMask;   // only the Ground layer

private bool IsGrounded() =>
    Physics.Raycast(transform.position, Vector3.down, out RaycastHit _, 1.1f,
                    groundMask, QueryTriggerInteraction.Ignore);

3. Kinematic platform that carries resting bodies (3D)

// isKinematic Rigidbody: MovePosition moves it through the solver, so bodies on top ride along.
private void FixedUpdate() =>
    _rb.MovePosition(_rb.position + Vector3.right * (2f * Time.fixedDeltaTime));

2D physics (Rigidbody2D)

Same rules, different types. The traps a 3D habit walks into:

3D 2D equivalent Difference that bites
Rigidbody.isKinematic Rigidbody2D.bodyType (Dynamic, Kinematic, Static) Rigidbody2D.isKinematic is obsolete; set bodyType
OnCollisionEnter(Collision) `OnCollisionEnter2D(Co
Полный SKILL.md на GitHub

Установить unity-physics в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/physics-2d.mdreferences/raycasting-and-joints.md

FAQ

Что делает скилл unity-physics?

Unity 6.3 LTS physics in 3D and 2D: Rigidbody and Rigidbody2D, forces and linearVelocity, the layer collision matrix and raycasts. Use when an object falls through the floor, OnTriggerEnter never fires, or a ground ray hits the player. Not for engine-neutral tunnelling tuning (`physics-tuning`), tilemap colliders (`unity-tilemap-2d`) or NavMesh (`unity-navmesh`).

Как установить скилл unity-physics?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл unity-physics запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить unity-physics с