Skip to content

t1k:unity:dots-rendering:perspective-2d-topdown

FieldValue
Moduledots-rendering
Version2.1.7
Efforthigh
Tools

Keywords: 2D, DOTS, perspective, top-down

/t1k:unity:dots-rendering:perspective-2d-topdown

  • 2D top-down, orthographic camera, sprite rendering, quad mesh, Y-sorting
  • SpriteAnimationSystem, SpriteColor, SpriteSheetUV, DeathFadeSystem
  • URP/Unlit cutout, alpha clip, flat rendering
  • Simulation: XZ plane (always). All navigation, physics, AI operate on XZ
  • Presentation: Camera looks down -Y axis. Entities are flat quads in XZ plane
  • No coordinate remapping — simulation coords = visual coords (unlike side-view)
  • Orthographic, rotation (90, 0, 0), position (0, height, 0)
  • farClipPlane = CameraHeight + 50f (must exceed camera Y position)
  • Camera uses Cinemachine 3.x (CinemachineCamera + CinemachinePositionComposer + CinemachineConfiner2D + CinemachineImpulseListener)
  • Bridge: CinemachineCameraBridge MonoBehaviour reads CameraTarget singleton → proxy Transform → CinemachineCamera.Follow
  • Auto-zoom: CinemachineAutoZoom MonoBehaviour queries alive DOTS entities → XZ AABB → cam.orthographicSize
  • CinemachineConfiner2D: BoxCollider2D must be on main scene (not SubScene)
  • → See references/camera-2d-topdown-guide.md and unity-cinemachine skill
  • Quad mesh in XZ plane: vertices at y=0, spanning (-0.5, 0, -0.5) to (0.5, 0, 0.5)
  • Shader: Universal Render Pipeline/Unlit — no lighting needed for top-down
  • Material mode: Opaque + AlphaTest (cutout) — enables SRP Batcher batching
  • Team color: White base material + per-entity SpriteColor [MaterialProperty("_BaseColor")]
  • Shadows: ShadowCastingMode.Off, receiveShadows = false on all quads -> See references/rendering-2d-topdown-guide.md
  • NavigationAuthoring.EnableGrounding = false — skip DOTSGroundingSystem (no Y physics)
  • RangedAttackAuthoring.ArcHeight = 0 + IsFlat = true — flat 2D projectile trajectory
  • Standard XZ NavMeshSurface on ground plane; NavMeshObstacle.carving = true for obstacles
  • MappingExtent must be proportional to arena size (200x200 arena needs ~50)
  • SpriteAnimationAuthoring for sprite sheet UV animation (FrameCount, Columns, FPS)
  • SpriteAnimationSystem advances frames via SpriteSheetUV [MaterialProperty("_BaseMap_ST")]
  • DeathFadeSystem lerps SpriteColor.Value.w (alpha) based on DeathAnimation.Remaining
  • Static sprites: set FrameCount = 1, FPS = 0
mesh.vertices = new[] {
new Vector3(-0.5f, 0f, -0.5f), new Vector3(0.5f, 0f, -0.5f),
new Vector3(-0.5f, 0f, 0.5f), new Vector3(0.5f, 0f, 0.5f),
};
mesh.triangles = new[] { 0, 2, 1, 2, 3, 1 };
mesh.normals = new[] { Vector3.up, Vector3.up, Vector3.up, Vector3.up };
mat.SetFloat("_Surface", 0f); // Opaque
mat.SetFloat("_AlphaClip", 1f); // Enable cutout
mat.SetFloat("_Cutoff", 0.5f);
mat.SetOverrideTag("RenderType", "TransparentCutout");
mat.renderQueue = (int)RenderQueue.AlphaTest;
mat.EnableKeyword("_ALPHATEST_ON");
mat.enableInstancing = true;
#IssueFix
1Camera farClipPlane < CameraHeight = invisible troopsSet farClipPlane = CameraHeight + 50f
2Transparent materials defeat SRP Batcher (608 batches)Use Opaque + AlphaTest cutout (28 batches)
3DetectionRadius < spawn gap = troops stand idleSet DetectionRadius > half the spawn gap distance
4Prefab regeneration wipes BDP treesAlways run “Build Behavior Trees” after “Create Unit Prefabs”
5while not if for SpriteAnimation frame advanceLarge deltaTime can skip multiple frames
6CinemachineConfiner2D references SubScene colliderBoxCollider2D for confiner MUST be in main scene
7Camera shake saturates with 500+ unitsHundreds of hits/frame × 0.03 trauma = instant max. Remove CinemachineImpulseListener from camera or set CameraTrauma.MaxIntensity=0
  • dots-ecs — ECS fundamentals
  • dots-rpg — SpriteAnimation, SpriteColor, SpriteSheetUV components
  • dots-graphics — Rendering fundamentals, MaterialProperty overrides
  • agents-navigation — Pathfinding, NavMesh setup
  • dots-performance — Batching, draw call optimization
  • unity-cinemachine — CinemachineCameraBridge, Confiner2D, impulse patterns
FileCoverage
references/rendering-2d-topdown-guide.mdSprite setup, materials, quad mesh, cutout vs transparent
references/camera-2d-topdown-guide.mdOrthographic setup, auto-zoom, bounds tracking