# 参数异常：地形碰撞器不支持负的地形高度值

- **ID:** `unity/terrain-collider-mismatch`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

地形数据高度图包含负值，地形碰撞器无法处理。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2022.3.0f1 | active | — | — |
| 2023.1.0b10 | active | — | — |
| 2021.3.20f1 | active | — | — |

## 解决方案

1. ```
   In Editor, select Terrain, open Terrain Settings, click 'Flatten' button to set all heights to 0, then re-paint heights with positive values. Alternatively, use script: TerrainData.SetHeights(0, 0, Mathf.Max(0, heights)).
   ```
2. ```
   Use a script to clamp negative heights: var heights = terrainData.GetHeights(0, 0, terrainData.heightmapResolution, terrainData.heightmapResolution); for (int y = 0; y < heights.GetLength(0); y++) for (int x = 0; x < heights.GetLength(1); x++) heights[y,x] = Mathf.Max(0.01f, heights[y,x]); terrainData.SetHeights(0, 0, heights);
   ```

## 无效尝试

- **Resetting TerrainCollider component in Inspector** — The issue is in TerrainData, not the collider component; resetting doesn't modify heightmap. (70% 失败率)
- **Deleting and recreating the terrain** — Loses all terrain data and work; the root cause (negative heights) must be fixed in data. (90% 失败率)
- **Setting TerrainCollider.enabled = false then true** — Only toggles collider state, does not address invalid height values. (80% 失败率)
