Godot 入門:VS Code と Codex 拡張で 2D ゲームを作る開発フロー

すでに VS Code に慣れているなら、Codex App だけに頼る必要はありません。この記事では、Godot 4.x、VS Code、godot-tools、Codex 拡張、Git を使った始め方と、2D 見下ろし型シューティングの開発サイクルを整理します。

すでに VS Code を日常的に使っているなら、Godot を学ぶためにまったく別の作業環境へ移る必要はありません。扱いやすい組み合わせは、Godot エディタでシーンとノードを作り、VS Code で GDScript を書き、Codex 拡張でプロジェクト分析、スクリプト生成、エラー調査、小さなリファクタリングを行う形です。

この方法では、最初から AI にゲーム全体を生成させません。より安定するのは、まず Godot 側で実際のノードツリーを作り、その既存シーン構造に合わせて Codex にスクリプトを書かせる進め方です。Codex がファイル構成を見られるため、ノード名やパスを推測で間違える可能性も下がります。

役割分担

VS Code ユーザーには、次の分担が向いています。

  • Godot:シーン、ノード、当たり判定、アニメーション、UI レイアウトを作る。
  • VS Code:GDScript を書き、管理する。
  • Codex:プロジェクトを分析し、スクリプト生成、エラー調査、小規模なリファクタリングを行う。
  • Git:動作する機能が 1 つ完成するたびにコミットする。

つまり、Godot はプロジェクトのメインエディタ、VS Code はコード作業環境、Codex は協調型のコーディングアシスタントとして使います。

VS Code 拡張をインストールする

VS Code には、まず 2 つの拡張を入れます。

  1. Codex

OpenAI 公式拡張です。現在のプロジェクト内のファイルを読み取り、編集し、必要なコマンドを実行できます。ChatGPT アカウントでログインします。

  1. godot-tools

Godot プロジェクトで GDScript を書くための拡張です。構文ハイライト、補完、定義ジャンプ、LSP 診断、VS Code からの Godot 起動とデバッグを提供します。

単なる GDScript ハイライト拡張だけで済ませず、優先して godot-tools を使いましょう。

Godot から VS Code を開く

Godot で次を開きます。

1
2
3
4
エディタ
→ エディタ設定
→ テキストエディタ
→ 外部

次を有効にします。

1
外部エディタを使用

Windows では、実行パスを code.cmd に向けます。ターミナルで確認できます。

1
where code.cmd

よくある結果は次のようなものです。

1
C:\Users\あなたのユーザー名\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd

実行引数には次を設定します。

1
{project} --goto {file}:{line}:{col}

Godot 4.5 以降では通常これらの引数を自動認識できますが、手動で入力しても問題ありません。

続けて次を開きます。

1
2
3
4
5
エディタ設定
→ テキストエディタ
→ 動作
→ ファイル
→ Auto Reload Scripts on External Change

外部で変更されたスクリプトを自動で再読み込みする設定を有効にします。これで Godot でスクリプトをダブルクリックすると、VS Code の該当ファイルと行へ移動できます。

VS Code でプロジェクトルートを開く

scripts フォルダだけを開かないでください。VS Code では、project.godot を含むプロジェクトルートを開く必要があります。

推奨構成:

1
2
3
4
5
6
7
my_game/
├─ project.godot
├─ AGENTS.md
├─ scenes/
├─ scripts/
├─ assets/
└─ .vscode/

開き方:

1
2
cd D:\GodotProjects\my_game
code .

その後、同じ Godot プロジェクトを Godot エディタでも開きます。

Godot の言語サーバーは、多くの場合、対象プロジェクトが Godot エディタで開かれていることを前提にします。既定の LSP ポートは 6005、DAP デバッグポートは 6006 です。通常の開発中は Godot エディタを開いたままにし、VS Code でコードを書きます。

VS Code デバッグを設定する

プロジェクトに次のファイルを作成します。

1
.vscode/launch.json

内容は次の通りです。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Godot プロジェクトを実行",
            "type": "godot",
            "request": "launch",
            "project": "${workspaceFolder}",
            "debugServer": 6006
        }
    ]
}

これで VS Code から F5 を押してゲームを起動し、デバッグできます。

F5 で Godot が見つからない場合は、VS Code 設定で次を検索します。

1
godotTools.editorPath.godot4

Godot 実行ファイルのパスを入力します。例:

1
D:\Programs\Godot\Godot_v4.7-stable_win64.exe

godot-tools は、この設定で Godot 4 エディタのパスを指定できます。

AGENTS.md を作る

プロジェクトルートに AGENTS.md を作成します。Codex が読むプロジェクトルールとして使います。

 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
# Godot Project Instructions

This is a Godot 4.x project using GDScript.

## Coding Rules

- Use only Godot 4.x APIs.
- Do not use old Godot 3.x syntax.
- Prefer static typing in GDScript.
- Use snake_case for variables and functions.
- Use PascalCase for class_name.
- Prefer @onready for node references.
- Use @export for configurable parameters.
- Do not rename existing nodes casually.
- Do not create an overly complex Manager architecture.
- Implement only one independently testable feature at a time.

## File Responsibilities

- scenes/ stores .tscn scenes.
- scripts/ stores .gd scripts.
- assets/ stores images, fonts, and sounds.
- ui/ stores UI scenes and UI scripts.

## Scene Modification Rules

- Before editing .tscn files, read and understand the existing node structure.
- Do not guess node names or NodePath values.
- For complex scenes, prefer telling the user to create nodes manually in the Godot editor.
- Unless the task explicitly asks for it, do not rewrite .tscn files broadly.

## Verification Rules

After finishing a task:

1. Check GDScript syntax.
2. Check resource paths and node paths.
3. List modified files.
4. Explain how to test in Godot.
5. Do not claim it ran successfully unless you actually verified it.

このファイルはかなり重要です。Codex にプロジェクトの境界を伝え、シーンの大幅な書き換え、構造の変更、古い Godot API の使用を減らせます。

先に Git を初期化する

VS Code のターミナルで実行します。

1
git init

.gitignore を作成します。

1
2
3
4
5
.godot/
.vscode/*.log
*.tmp
export/
build/

最初のコミット:

1
2
git add .
git commit -m "初始化 Godot 项目"

Codex にプロジェクトを変更させる前に、Git のチェックポイントを作っておきます。試行錯誤をすぐ戻せるので、安心して進められます。

最初のプロジェクトは 2D がおすすめ

VS Code に慣れていても、最初の Godot プロジェクトは 2D から始めるのがおすすめです。大規模な 3D プロジェクト、複雑な UI、完全な RPG システムから始める必要はありません。

練習に向いている題材は次です。

1
2D 見下ろし型シューティングのプロトタイプ

最小機能:

  • プレイヤー移動
  • マウス照準
  • 弾の発射
  • 敵の追跡
  • 衝突ダメージ
  • スコア
  • リスタート

推奨ディレクトリ:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
my_game/
├─ project.godot
├─ AGENTS.md
├─ scenes/
│  ├─ main.tscn
│  ├─ player.tscn
│  ├─ bullet.tscn
│  └─ enemy.tscn
├─ scripts/
│  ├─ main.gd
│  ├─ player.gd
│  ├─ bullet.gd
│  └─ enemy.gd
├─ ui/
│  └─ hud.tscn
└─ assets/

Codex への最初のプロンプト

VS Code の Codex パネルでは、最初からコードを書かせないようにします。まずプロジェクトを読ませ、作業を分解し、境界を確認させます。

次のように依頼します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
This is a new Godot 4.x GDScript project.

I want to build a minimal 2D top-down shooter.

Do not modify files yet.

First complete the following:

1. Read project.godot and the current directory structure.
2. Check whether the project already has a main scene configured.
3. Design the minimum viable version.
4. Break the work into small tasks that can each be run and verified independently.
5. Clarify which nodes I should create manually in the Godot editor.
6. Clarify which scripts are suitable for you to write.
7. Use only Godot 4.x APIs.
8. Do not generate the whole game at once.
9. Do not directly write complex .tscn files.

Codex の分析が終わったら、最初の機能だけを依頼します。まずはプレイヤー移動です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Now implement only player movement.

Scene structure:

Player: CharacterBody2D
├─ Sprite2D
└─ CollisionShape2D

Script path:
scripts/player.gd

Requirements:

- Use Input.get_vector
- Use move_and_slide
- Use static typing
- Use @export for movement speed
- Do not rename scene nodes
- Do not implement shooting, health, or animation
- After editing, tell me which Input Map actions I need to configure
- Provide test steps

重要なのは「1 回に 1 機能だけ」です。早い段階で範囲を絞るほど、Codex の変更は検証しやすくなります。

おすすめの開発サイクル

毎回 1 つの機能だけを作ります。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Godot でノードを作る
VS Code で Codex にスクリプトを書かせる
Git diff を確認する
F5 で実行する
完全なエラーを Codex に渡す
最小修正を依頼する
動いたら Git commit

デバッグ時は、次のプロンプトを使えます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
The following runtime error occurred:

Paste the full error message

Please identify the root cause first.

Requirements:
- Check the actual node structure and NodePath values;
- Make only the smallest change;
- Do not refactor unrelated code;
- Do not modify features that already work;
- After editing, explain why the error happened.

「エラーが出た」だけでは足りません。完全なエラー、シーン構造、関連スクリプトのパスを一緒に渡すと、Codex は問題を特定しやすくなります。

Codex の権限設定

Codex 拡張を使い始めたばかりなら、まず通常の Agent モードを使うのがおすすめです。

最初から Agent Full Access を長時間使い続ける必要はありません。通常の Agent モードでも、ファイルの読み取り、プロジェクトの編集、許可されたコマンドの実行はできます。Full Access は、タスクの境界が明確になってから一時的に使うほうが向いています。

最初の組み合わせは次で十分です。

  • Godot 4.x
  • GDScript
  • VS Code
  • godot-tools
  • Codex
  • Git

最初に C# を学ぶ必要はありません。Codex にシーン全体を自動生成させる必要もありません。まず Godot でノードツリーを作り、その実際の構造に合わせて Codex にスクリプトを書かせるほうが、成功率は高くなります。

记录并分享
Hugo で構築されています。
テーマ StackJimmy によって設計されています。