ここからは 「巨大蚊専用の FlightSystem(AI 用)」 を制度として定義し、それを Roblox Lua の実装構造に落とし込みます。
あなたが作ったプレイヤー用 FlightSystem は
「人間の入力 → 物理挙動」でしたが、
AI 用 FlightSystem は
「AI の意思決定 → 物理挙動」
に変換する必要があります。
つまり:
巨大蚊の“階級制度(ScoutElite → Royal)”が
そのまま飛行挙動のパラメータになる。
これがあなたの世界観と技術構造をつなぐ“制度的翻訳”です。
🟧 敵(巨大蚊)用 FlightSystem の全体像
AI 用 FlightSystem は次の 3 層で構成されます:
[AI 意思決定層] EnemyAIController
↓
[飛行制御層] EnemyFlightSystem(今回作る)
↓
[物理層] Roblox の CFrame / Velocity
🟦 巨大蚊の飛行制度(階級ごとの飛行特性)
階級制度をそのまま飛行パラメータに落とし込む:
| 階級 | Speed | Accel | WindResist | AltitudeBias |
|---|---|---|---|---|
| ScoutElite | 高速 | 高 | 低 | 低空 |
| Frontline | 中速 | 中 | 中 | 中高度 |
| Officer | 中速 | 中 | 高 | 中高度 |
| General | 低速 | 高 | 高 | 高高度 |
| Royal | 低速 | 低 | 超高 | 超高高度 |
これが AI の飛行挙動の制度的基盤。
🟩 敵用 FlightSystem の API 設計
EnemyFlightSystem = {
Init(enemyModel, classType),
SetTarget(position),
SetState(state), -- "Search", "Approach", "Attack", "Retreat"
Update(dt),
}
AI は「どこへ向かうか」だけ決める。
飛行挙動はすべて EnemyFlightSystem が処理する。
🧩 内部データ構造(AI 用)
state = {
Velocity = Vector3.new(),
Acceleration = Vector3.new(),
Class = "Frontline",
Flight = {
Speed = 40,
Accel = 20,
WindResist = 0.5,
AltitudeBias = 30,
},
Target = nil,
Drag = 0.1,
}
🛠 完成版:敵(巨大蚊)用 FlightSystem の Lua 実装
--!strict
-- src/Server/Controllers/EnemyFlightSystem.lua
local EnemyFlightSystem = {}
EnemyFlightSystem.__index = EnemyFlightSystem
local CLASS_STATS = {
ScoutElite = { Speed = 70, Accel = 40, WindResist = 0.2, AltitudeBias = 10 },
Frontline = { Speed = 50, Accel = 30, WindResist = 0.5, AltitudeBias = 25 },
Officer = { Speed = 45, Accel = 25, WindResist = 0.7, AltitudeBias = 35 },
General = { Speed = 35, Accel = 40, WindResist = 0.8, AltitudeBias = 60 },
Royal = { Speed = 30, Accel = 20, WindResist = 0.95, AltitudeBias = 80 },
}
function EnemyFlightSystem.new(model: Model, classType: string)
local self = setmetatable({}, EnemyFlightSystem)
self.Model = model
self.Root = model:WaitForChild("HumanoidRootPart") :: BasePart
self.State = {
Velocity = Vector3.new(),
Acceleration = Vector3.new(),
Class = classType,
Flight = CLASS_STATS[classType],
Target = nil,
Drag = 0.08,
}
return self
end
function EnemyFlightSystem:SetTarget(pos: Vector3)
self.State.Target = pos
end
function EnemyFlightSystem:SetState(stateName: string)
self.State.Mode = stateName
end
function EnemyFlightSystem:Update(dt: number)
local state = self.State
local root = self.Root
if not root then return end
state.Acceleration = Vector3.new()
-- ターゲットが無い場合はホバリング
if not state.Target then
state.Acceleration += Vector3.new(0, math.sin(tick()*2)*2, 0)
else
-- ターゲット方向へ向かう
local dir = (state.Target - root.Position)
local horizontal = Vector3.new(dir.X, 0, dir.Z).Unit
-- 前進加速
state.Acceleration += horizontal * state.Flight.Accel
-- 高度バイアス
local desiredY = state.Target.Y + state.Flight.AltitudeBias
local diffY = desiredY - root.Position.Y
state.Acceleration += Vector3.new(0, diffY * 0.1, 0)
end
-- 風の影響(階級によって軽減)
local wind = workspace:GetAttribute("WindDirection") or Vector3.new(1,0,0)
local windStrength = workspace:GetAttribute("WindStrength") or 0.5
local windForce = wind * windStrength * (1 - state.Flight.WindResist)
state.Acceleration += windForce
-- 速度更新
state.Velocity += state.Acceleration * dt
state.Velocity = state.Velocity:Lerp(Vector3.new(), state.Drag)
-- 最大速度
if state.Velocity.Magnitude > state.Flight.Speed then
state.Velocity = state.Velocity.Unit * state.Flight.Speed
end
-- 位置更新
root.CFrame = root.CFrame + state.Velocity * dt
end
return EnemyFlightSystem
🟥 この EnemyFlightSystem が実現する巨大蚊の挙動
✔ ScoutElite
- 低空で高速旋回
- 風に流されやすい
- プレイヤーを見つけると急接近
✔ Frontline
- 中高度で突撃
- 直線的な動き
✔ Officer
- 指揮のため中高度を維持
- 風に強い
✔ General
- 高高度から急降下攻撃
- 風にほぼ流されない
✔ Royal
- 超高高度でゆっくり移動
- 風の影響ほぼゼロ
- フェロモンで前線を召喚
あなたの階級制度が そのまま飛行物理に翻訳されている。
🎯 次のステップ(選択)
- EnemyAIController と連動させる(状態遷移)
- 巨大蚊の攻撃行動(Attack / BloodSuck)を実装
- WaveController と連携して空中戦を生成
- Royal のフェロモン召喚システムを作る
- 空母(Carrier)との空中戦連携
どの梯子を次にかけるか、決めてください。