SRPGのカメラ制御は、操作性を左右します。
戦場全体が見渡せないと、戦略が立てられません。
この記事では、実装方法を詳しく解説します。
✨ この記事でわかること
- グリッド全体を見渡せるカメラ設定
- ズーム・回転・スクロールの実装
- ユニット選択時のカメラ追従
- 操作性と見やすさのバランス
- 実装例とコード

カメラ制御は、プレイヤーの体験を大きく左右します。まずは基本的な操作から実装しましょう。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
あなたのオリジナルゲーム、今年こそ完成させませんか?
RPG・アクション・ホラー…Unityで本格ゲームを作りたい人のための学習サイトです。
実際に完成するゲームを題材に、
ソースコード・素材・プロジェクト一式をすべて公開。
仕事や学校の合間の1〜2時間でも、
「写経→改造」で自分のゲームまで作りきれる環境です。
グリッド全体を見渡せるカメラ設定

まずは、グリッド全体が見渡せるカメラ設定をします。
実装方法を紹介します。
カメラの基本設定
- Hierarchyで「Main Camera」を選択
- Projectionを「Orthographic」に変更(2D用)
- Sizeを10に設定(グリッド全体が見えるように)
- Positionを(5, 10, 5)に設定(斜め上から見下ろす)
- Rotationを(45, -45, 0)に設定(アイソメトリック視点)
この設定で、グリッド全体が見渡せます。
アイソメトリック視点(斜め上から見下ろす)が、SRPGに適しています。
カメラスクリプトの実装
|
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 73 74 75 76 77 78 79 |
using UnityEngine; public class SRPGCamera : MonoBehaviour { [Header("カメラ設定")] public float cameraHeight = 10f; public float cameraAngle = 45f; public float cameraDistance = 10f; [Header("移動設定")] public float moveSpeed = 5f; public float scrollSpeed = 2f; private Camera cam; private Vector3 targetPosition; void Start() { cam = GetComponent<Camera>(); cam.orthographic = true; cam.orthographicSize = 10f; // 初期位置を設定 targetPosition = new Vector3(5f, cameraHeight, 5f); transform.position = targetPosition; transform.rotation = Quaternion.Euler(cameraAngle, -45f, 0f); } void Update() { // カメラ移動 HandleCameraMovement(); // ズーム HandleZoom(); } void HandleCameraMovement() { Vector3 moveDirection = Vector3.zero; // WASDキーで移動 if (Input.GetKey(KeyCode.W)) moveDirection += Vector3.forward; if (Input.GetKey(KeyCode.S)) moveDirection += Vector3.back; if (Input.GetKey(KeyCode.A)) moveDirection += Vector3.left; if (Input.GetKey(KeyCode.D)) moveDirection += Vector3.right; // 移動方向をカメラの向きに合わせる Vector3 cameraForward = transform.forward; cameraForward.y = 0; cameraForward.Normalize(); Vector3 cameraRight = transform.right; cameraRight.y = 0; cameraRight.Normalize(); Vector3 worldMove = cameraForward * moveDirection.z + cameraRight * moveDirection.x; targetPosition += worldMove * moveSpeed * Time.deltaTime; // スムーズに移動 transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 5f); } void HandleZoom() { float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0) { cam.orthographicSize -= scroll * scrollSpeed; cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, 5f, 20f); } } } |
このコードで、基本的なカメラ操作が実装できます。
WASDキーで移動、マウスホイールでズームできます。
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 |
public class SRPGCamera : MonoBehaviour { [Header("回転設定")] public float rotationSpeed = 50f; public bool enableRotation = true; private Vector3 lastMousePosition; private bool isRotating = false; void Update() { HandleRotation(); } void HandleRotation() { if (!enableRotation) return; // 右クリックで回転 if (Input.GetMouseButtonDown(1)) { isRotating = true; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButton(1) && isRotating) { Vector3 delta = Input.mousePosition - lastMousePosition; float rotationY = delta.x * rotationSpeed * Time.deltaTime; // Y軸を中心に回転 transform.RotateAround(GetCameraFocusPoint(), Vector3.up, rotationY); lastMousePosition = Input.mousePosition; } if (Input.GetMouseButtonUp(1)) { isRotating = false; } } Vector3 GetCameraFocusPoint() { // カメラの注視点(グリッドの中心など) return new Vector3(5f, 0f, 5f); } } |
右クリックでドラッグすると、カメラが回転します。
グリッドの中心を軸に回転します。
マウスドラッグによるスクロール
|
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 |
public class SRPGCamera : MonoBehaviour { [Header("スクロール設定")] public float scrollSpeed = 5f; public bool enableScroll = true; private Vector3 lastMousePosition; private bool isScrolling = false; void Update() { HandleScroll(); } void HandleScroll() { if (!enableScroll) return; // 中クリックでスクロール if (Input.GetMouseButtonDown(2)) { isScrolling = true; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButton(2) && isScrolling) { Vector3 delta = Input.mousePosition - lastMousePosition; // カメラの向きに合わせて移動 Vector3 moveDirection = -transform.right * delta.x * scrollSpeed * Time.deltaTime; moveDirection += -transform.forward * delta.y * scrollSpeed * Time.deltaTime; moveDirection.y = 0; targetPosition += moveDirection; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButtonUp(2)) { isScrolling = false; } } } |
中クリックでドラッグすると、カメラがスクロールします。
マウスの移動方向に、カメラが移動します。
✅ カメラ操作の推奨設定
- WASDキー:カメラ移動
- マウスホイール:ズーム
- 右クリックドラッグ:回転
- 中クリックドラッグ:スクロール
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 |
public class SRPGCamera : MonoBehaviour { private Unit targetUnit; private bool isFollowing = false; public float followSpeed = 5f; public float followHeight = 10f; public void FollowUnit(Unit unit) { targetUnit = unit; isFollowing = true; } public void StopFollowing() { isFollowing = false; targetUnit = null; } void Update() { if (isFollowing && targetUnit != null) { Vector3 targetPos = gridMap.GetWorldPosition(targetUnit.gridX, targetUnit.gridY); targetPos.y = followHeight; // スムーズに追従 transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * followSpeed); } } } |
ユニットを選択すると、カメラが自動で追従します。
スムーズに移動するため、見やすくなります。
ユニット選択との連携
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public class UnitSelector : MonoBehaviour { public SRPGCamera camera; public void OnUnitSelected(Unit unit) { // カメラを追従させる camera.FollowUnit(unit); // 移動範囲を表示 ShowMoveRange(unit); } public void OnUnitDeselected() { // カメラの追従を停止 camera.StopFollowing(); } } |
ユニット選択とカメラ追従を連携させます。
選択したユニットに、カメラが自動で移動します。

カメラ追従は、プレイヤーの操作を減らします。ただし、自動移動が煩わしい場合は、オプションで無効化できるようにしましょう。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
操作性と見やすさのバランス

操作性と見やすさのバランスが重要です。
調整方法を紹介します。
カメラの制限範囲
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class SRPGCamera : MonoBehaviour { [Header("制限範囲")] public float minX = 0f; public float maxX = 10f; public float minZ = 0f; public float maxZ = 10f; void Update() { HandleCameraMovement(); // 範囲制限 ClampCameraPosition(); } void ClampCameraPosition() { targetPosition.x = Mathf.Clamp(targetPosition.x, minX, maxX); targetPosition.z = Mathf.Clamp(targetPosition.z, minZ, maxZ); } } |
カメラの移動範囲を制限します。
グリッド外に移動しないようにします。
ズームの制限
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public class SRPGCamera : MonoBehaviour { [Header("ズーム制限")] public float minZoom = 5f; public float maxZoom = 20f; void HandleZoom() { float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0) { cam.orthographicSize -= scroll * scrollSpeed; cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, minZoom, maxZoom); } } } |
ズームの範囲を制限します。
最小5、最大20が標準です。
- 最小ズーム:5(近くが見える)
- 最大ズーム:20(全体が見える)
- 標準ズーム:10(バランスが良い)
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
using UnityEngine; public class CompleteSRPGCamera : MonoBehaviour { [Header("カメラ設定")] public float cameraHeight = 10f; public float cameraAngle = 45f; public float moveSpeed = 5f; public float scrollSpeed = 2f; public float rotationSpeed = 50f; [Header("制限")] public float minZoom = 5f; public float maxZoom = 20f; public float minX = 0f; public float maxX = 10f; public float minZ = 0f; public float maxZ = 10f; [Header("追従設定")] public float followSpeed = 5f; public bool autoFollow = true; private Camera cam; private Vector3 targetPosition; private Unit targetUnit; private bool isFollowing = false; private bool isRotating = false; private bool isScrolling = false; private Vector3 lastMousePosition; private GridMap gridMap; void Start() { cam = GetComponent<Camera>(); cam.orthographic = true; cam.orthographicSize = 10f; gridMap = FindObjectOfType<GridMap>(); targetPosition = new Vector3(5f, cameraHeight, 5f); transform.position = targetPosition; transform.rotation = Quaternion.Euler(cameraAngle, -45f, 0f); } void Update() { HandleCameraMovement(); HandleZoom(); HandleRotation(); HandleScroll(); HandleFollow(); ClampCameraPosition(); } void HandleCameraMovement() { Vector3 moveDirection = Vector3.zero; if (Input.GetKey(KeyCode.W)) moveDirection += Vector3.forward; if (Input.GetKey(KeyCode.S)) moveDirection += Vector3.back; if (Input.GetKey(KeyCode.A)) moveDirection += Vector3.left; if (Input.GetKey(KeyCode.D)) moveDirection += Vector3.right; if (moveDirection != Vector3.zero) { Vector3 cameraForward = transform.forward; cameraForward.y = 0; cameraForward.Normalize(); Vector3 cameraRight = transform.right; cameraRight.y = 0; cameraRight.Normalize(); Vector3 worldMove = cameraForward * moveDirection.z + cameraRight * moveDirection.x; targetPosition += worldMove * moveSpeed * Time.deltaTime; } transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 5f); } void HandleZoom() { float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0) { cam.orthographicSize -= scroll * scrollSpeed; cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, minZoom, maxZoom); } } void HandleRotation() { if (Input.GetMouseButtonDown(1)) { isRotating = true; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButton(1) && isRotating) { Vector3 delta = Input.mousePosition - lastMousePosition; float rotationY = delta.x * rotationSpeed * Time.deltaTime; Vector3 focusPoint = new Vector3(5f, 0f, 5f); transform.RotateAround(focusPoint, Vector3.up, rotationY); lastMousePosition = Input.mousePosition; } if (Input.GetMouseButtonUp(1)) { isRotating = false; } } void HandleScroll() { if (Input.GetMouseButtonDown(2)) { isScrolling = true; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButton(2) && isScrolling) { Vector3 delta = Input.mousePosition - lastMousePosition; Vector3 moveDirection = -transform.right * delta.x * scrollSpeed * Time.deltaTime; moveDirection += -transform.forward * delta.y * scrollSpeed * Time.deltaTime; moveDirection.y = 0; targetPosition += moveDirection; lastMousePosition = Input.mousePosition; } if (Input.GetMouseButtonUp(2)) { isScrolling = false; } } void HandleFollow() { if (isFollowing && targetUnit != null && autoFollow) { Vector3 targetPos = gridMap.GetWorldPosition(targetUnit.gridX, targetUnit.gridY); targetPos.y = cameraHeight; targetPosition = Vector3.Lerp(targetPosition, targetPos, Time.deltaTime * followSpeed); } } void ClampCameraPosition() { targetPosition.x = Mathf.Clamp(targetPosition.x, minX, maxX); targetPosition.z = Mathf.Clamp(targetPosition.z, minZ, maxZ); } public void FollowUnit(Unit unit) { targetUnit = unit; isFollowing = true; } public void StopFollowing() { isFollowing = false; targetUnit = null; } } |
このコードで、完全なカメラシステムが実装できます。
移動・ズーム・回転・スクロール・追従のすべてに対応しています。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる
よくある質問(FAQ)

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

カメラ制御は、操作性と見やすさのバランスが重要です。
まずは基本的な操作から実装して、徐々に機能を追加しましょう。
✅ 今日から始める3ステップ
- ステップ1:カメラの基本設定をする(所要30分)
- ステップ2:WASDキーでの移動を実装する(所要1時間)
- ステップ3:ズームと回転を実装する(所要2時間)
本格的にUnityを学びたい方は、Unity入門の森で実践的なスキルを身につけましょう。
あなたのペースで、少しずつ進めていけば大丈夫です。
Unity入門の森を見る 初心者歓迎!動画×プロジェクト一式で本格ゲーム制作を学べる



コメント