地形効果は、SRPGの戦略性を高めます。
回避補正、移動コスト、視界を実装すれば、深みのあるバトルが作れます。
この記事では、実装方法を詳しく解説します。
✨ この記事でわかること
- 地形データの設計
- 回避補正の実装
- 移動コストの実装
- 視界システムの実装
- 実装例とコード

地形効果は、データテーブルで管理しましょう。これにより、調整が簡単になり、拡張もしやすくなります。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
あなたのオリジナルゲーム、今年こそ完成させませんか?
RPG・アクション・ホラー…Unityで本格ゲームを作りたい人のための学習サイトです。
実際に完成するゲームを題材に、
ソースコード・素材・プロジェクト一式をすべて公開。
仕事や学校の合間の1〜2時間でも、
「写経→改造」で自分のゲームまで作りきれる環境です。
地形データの設計

地形データの設計は、システムの基礎です。
設計方法を紹介します。
地形データ構造
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
using UnityEngine; [CreateAssetMenu(fileName = "NewTerrain", menuName = "SRPG/Terrain")] public class TerrainData : ScriptableObject { [Header("基本情報")] public string terrainName; public TerrainType terrainType; [Header("戦闘効果")] public float evasionBonus = 0f; // 回避補正(%) public float accuracyBonus = 0f; // 命中補正(%) public float damageBonus = 0f; // ダメージ補正(%) [Header("移動")] public int moveCost = 1; // 移動コスト public bool isPassable = true; // 通行可能か [Header("視界")] public int visionRange = 1; // 視界範囲 public bool blocksVision = false; // 視界を遮るか } public enum TerrainType { Plain, // 平地 Grass, // 草原 Forest, // 森 Mountain,// 山 Water, // 水 Wall // 壁 } |
このコードで、地形データ構造が定義できます。
ScriptableObjectで管理すれば、デザイナーも編集できます。
地形の種類と効果
✅ 基本地形の効果
- 平地:回避+0%、移動コスト1、視界+0
- 草原:回避+5%、移動コスト1、視界+0
- 森:回避+15%、移動コスト2、視界-1
- 山:回避+10%、移動コスト3、視界+1
- 水:回避-10%、移動コスト4、視界+0
地形の種類を増やすことで、戦略性が高まります。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
回避補正の実装

回避補正は、地形に応じて回避率が変化します。
実装方法を紹介します。
回避率計算システム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
public class EvasionCalculator : MonoBehaviour { public float CalculateEvasionRate(Unit unit, TerrainData terrain) { // 基本回避率 float baseEvasion = unit.evasion; // 地形補正を適用 float terrainBonus = terrain.evasionBonus; float finalEvasion = baseEvasion + terrainBonus; // 0〜100%の範囲に制限 finalEvasion = Mathf.Clamp(finalEvasion, 0f, 100f); return finalEvasion; } public bool CheckEvasion(Unit attacker, Unit defender, TerrainData defenderTerrain) { float evasionRate = CalculateEvasionRate(defender, defenderTerrain); float random = Random.Range(0f, 100f); return random < evasionRate; } public void ApplyEvasion(Unit attacker, Unit defender, TerrainData defenderTerrain) { if (CheckEvasion(attacker, defender, defenderTerrain)) { Debug.Log($"{defender.unitName}は回避しました!(地形: {defenderTerrain.terrainName})"); // 回避処理 } else { // 命中処理 Debug.Log($"{attacker.unitName}の攻撃が命中しました"); } } } |
このコードで、回避補正が実装できます。
地形に応じて、回避率が変化します。

回避補正は、防御側の地形を参照します。森にいるユニットは、回避率が上がります。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
移動コストの実装

移動コストは、地形に応じて移動力が消費されます。
実装方法を紹介します。
移動コスト計算システム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
public class MovementCostCalculator : MonoBehaviour { public GridSystem gridSystem; public int CalculatePathCost(List<Vector2Int> path) { int totalCost = 0; foreach (var pos in path) { TerrainData terrain = gridSystem.GetTerrainAt(pos); if (terrain != null) { totalCost += terrain.moveCost; } } return totalCost; } public bool CanReach(Unit unit, Vector2Int targetPos) { List<Vector2Int> path = FindPath(unit.position, targetPos); if (path == null || path.Count == 0) { return false; } int pathCost = CalculatePathCost(path); return pathCost <= unit.moveRange; } public List<Vector2Int> FindPath(Vector2Int start, Vector2Int end) { // A*アルゴリズムでパスを検索 // 実装は省略 return null; } } |
このコードで、移動コスト計算が実装できます。
パスの移動コストを計算し、移動可能か判定します。
移動可能範囲の表示
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
public class MovementRangeDisplay : MonoBehaviour { public GridSystem gridSystem; public MovementCostCalculator costCalculator; public List<Vector2Int> GetMovableTiles(Unit unit) { List<Vector2Int> movableTiles = new List<Vector2Int>(); // ユニットの周囲を探索 for (int x = -unit.moveRange; x <= unit.moveRange; x++) { for (int z = -unit.moveRange; z <= unit.moveRange; z++) { Vector2Int targetPos = new Vector2Int( unit.position.x + x, unit.position.y + z ); if (costCalculator.CanReach(unit, targetPos)) { movableTiles.Add(targetPos); } } } return movableTiles; } public void HighlightMovableTiles(Unit unit) { List<Vector2Int> movableTiles = GetMovableTiles(unit); foreach (var pos in movableTiles) { // タイルをハイライト // 実装は省略 } } } |
このコードで、移動可能範囲の表示が実装できます。
ユニットの移動可能範囲を、視覚的に表示します。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
視界システムの実装

視界システムは、地形に応じて視界範囲が変化します。
実装方法を紹介します。
視界計算システム
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
public class VisionSystem : MonoBehaviour { public GridSystem gridSystem; public int CalculateVisionRange(Unit unit, TerrainData terrain) { // 基本視界範囲 int baseVision = unit.visionRange; // 地形補正を適用 int terrainBonus = terrain.visionRange; int finalVision = baseVision + terrainBonus; // 最小値は1 finalVision = Mathf.Max(finalVision, 1); return finalVision; } public List<Vector2Int> GetVisibleTiles(Unit unit) { List<Vector2Int> visibleTiles = new List<Vector2Int>(); TerrainData terrain = gridSystem.GetTerrainAt(unit.position); int visionRange = CalculateVisionRange(unit, terrain); // 視界範囲内のタイルを取得 for (int x = -visionRange; x <= visionRange; x++) { for (int z = -visionRange; z <= visionRange; z++) { float distance = Mathf.Sqrt(x * x + z * z); if (distance <= visionRange) { Vector2Int pos = new Vector2Int(unit.position.x + x, unit.position.y + z); // 視界を遮る地形をチェック if (!IsVisionBlocked(unit.position, pos)) { visibleTiles.Add(pos); } } } } return visibleTiles; } bool IsVisionBlocked(Vector2Int from, Vector2Int to) { // パス上の地形をチェック List<Vector2Int> path = GetLinePath(from, to); foreach (var pos in path) { TerrainData terrain = gridSystem.GetTerrainAt(pos); if (terrain != null && terrain.blocksVision) { return true; } } return false; } List<Vector2Int> GetLinePath(Vector2Int from, Vector2Int to) { // ブレゼンハムのアルゴリズムで直線パスを取得 // 実装は省略 return new List<Vector2Int>(); } } |
このコードで、視界システムが実装できます。
地形に応じて、視界範囲が変化します。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
実装例:完全な地形効果システム

実際に使える、完全な地形効果システムの実装例を紹介します。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using UnityEngine; public class CompleteTerrainEffectSystem : MonoBehaviour { [Header("システム")] public GridSystem gridSystem; public EvasionCalculator evasionCalculator; public MovementCostCalculator movementCalculator; public VisionSystem visionSystem; public void ApplyTerrainEffects(Unit unit) { TerrainData terrain = gridSystem.GetTerrainAt(unit.position); if (terrain == null) { return; } // 回避補正を適用 float evasionRate = evasionCalculator.CalculateEvasionRate(unit, terrain); unit.currentEvasion = evasionRate; // 視界範囲を更新 int visionRange = visionSystem.CalculateVisionRange(unit, terrain); unit.currentVisionRange = visionRange; // 移動可能範囲を更新 movementCalculator.UpdateMovableRange(unit); } } |
このコードで、完全な地形効果システムが実装できます。
回避補正、移動コスト、視界を統合しています。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
よくある質問(FAQ)

Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
あなたのオリジナルゲーム、今年こそ完成させませんか?
RPG・アクション・ホラー…Unityで本格ゲームを作りたい人のための学習サイトです。
実際に完成するゲームを題材に、
ソースコード・素材・プロジェクト一式をすべて公開。
仕事や学校の合間の1〜2時間でも、
「写経→改造」で自分のゲームまで作りきれる環境です。
まとめ

地形効果は、データテーブルで管理しましょう。
これにより、調整が簡単になり、拡張もしやすくなります。
✅ 今日から始める3ステップ
- ステップ1:地形データ構造を設計する(所要2時間)
- ステップ2:回避補正システムを実装する(所要2時間)
- ステップ3:移動コストシステムを実装する(所要3時間)
本格的にUnityを学びたい方は、Unity入門の森で実践的なスキルを身につけましょう。
あなたのペースで、少しずつ進めていけば大丈夫です。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる



コメント