---
description: Physics and Rendering
alwaysApply: false
---

# Physics and Rendering

Guidelines for physics systems, collision management, render pipelines, and shaders in Unity.

## Core Principles

- Use physics for physics, not gameplay triggers (prefer overlap queries)
- Always set collision layers and layer masks to avoid unnecessary checks
- Select the render pipeline at project start; switching later is costly
- Profile GPU on target hardware, not in the Editor

## Physics System Selection

| Need | Recommended | Notes |
|------|-------------|-------|
| Player movement (arcade) | CharacterController | Built-in slopes, steps |
| Player movement (realistic) | Rigidbody + capsule | Responds to forces |
| Hitscan weapons | Physics.Raycast | Instant, use NonAlloc |
| Slow projectiles | Rigidbody + collider | Gravity, bounce for free |
| Fast projectiles | Raycast per frame | Prevents tunneling |
| Area detection | OverlapSphere/Box | No rigidbody needed |

## Render Pipeline Comparison

| Feature | URP | HDRP | Built-in |
|---------|-----|------|----------|
| Targets | All platforms | PC, Console | Legacy only |
| SRP Batcher | Yes | Yes | No |
| Ray tracing | Limited | Full | No |
| Custom passes | RenderFeature | CustomPass | CommandBuffer |

## Lighting Strategy

- **Static light?** Baked lightmaps (best performance)
- **Dynamic, few objects?** Realtime point/spot (limit range)
- **Dynamic, many objects?** Mixed lighting (bake indirect, realtime direct)
- **VR**: Baked strongly preferred; realtime shadows expensive at 90 FPS

## LOD Guidelines

| Level | Screen % | Detail |
|-------|----------|--------|
| LOD0 | 0-15% | Full mesh, all VFX |
| LOD1 | 15-30% | 50% polys, simplified VFX |
| LOD2 | 30-60% | 25% polys, no VFX |
| Culled | >60% | Not rendered |

## Common Pitfalls

**Moving Static Colliders**: Moving a collider without a Rigidbody rebuilds the collision tree every frame. Add Kinematic Rigidbody to moving colliders.

**Mesh Colliders on Dynamic Objects**: Expensive and limited. Approximate with box/sphere/capsule compound colliders.

**No Layer Masks on Raycasts**: `Physics.Raycast(ray, out hit, 100f)` checks everything. Always pass a layer mask.
