🚦 Kurz & knapp
• Roblox-Studio akzeptiert nur Lua, kein Python
• Die “Command Bar” (unten in Studio) oder der In-Game-Chat können zum Steuern benutzt werden
• Darum musst du deinen Simulator in Lua nachbauen. Unten findest du ein 1-zu-1-“Port” deines Python-Beispiels + Autopilot-Modus und Chat-Befehlen.
1. Projektstruktur in Roblox-Studio
Workspace
├─ Agent ↔ Model mit PrimaryPart (deine Spielfigur)
├─ Goal ↔ Part / Dummy-Ziel
└─ Obstacles ↔ Folder mit Hindernis-Parts
ServerScriptService
├─ Simulator ↔ ModuleScript
└─ Main ↔ Script (lädt das ModuleScript)
Tipp: View → Command Bar aktivieren (unten). Im Play-Modus kannst du jede Lua-Zeile dort ausführen.
Im Live-Spiel steuern wir per Chat-Nachricht (“gehe nach norden”, “autonom” …).
2. ModuleScript „Simulator“
-- ServerScriptService/Simulator
local Simulator = {}
Simulator.__index = Simulator
--------------------------------------------------
-- Konstruktor -----------------------------------
--------------------------------------------------
function Simulator.new(agentModel, goalPart, obstacleFolder)
local self = setmetatable({}, Simulator)
self.agent = agentModel -- Model
self.goalPart = goalPart -- Part
self.obstacles = obstacleFolder:GetChildren() -- Tabelle aller Hindernis-Parts
self.state = {
position = agentModel.PrimaryPart.Position, -- Vector3
goal = goalPart.Position, -- Vector3
}
return self
end
--------------------------------------------------
-- Hilfsfunktionen ------------------------------
--------------------------------------------------
local STEP = 4 -- 4 Studs pro Schritt
local function vec(x, z) -- 2D-Hilfsvektor (Y bleibt gleich)
return Vector3.new(x, 0, z)
end
function Simulator:isObstacle(pos)
for _, part in ipairs(self.obstacles) do
if (part.Position - pos).Magnitude < STEP * 0.5 then
return true
end
end
return false
end
--------------------------------------------------
-- Öffentliche API -------------------------------
--------------------------------------------------
function Simulator:updateState(tbl)
for k, v in pairs(tbl) do
self.state[k] = v
end
end
function Simulator:executeAction(action)
local p = self.state.position
local dir = {
move_north = vec( 0, -STEP),
move_south = vec( 0, STEP),
move_east = vec( STEP, 0),
move_west = vec(-STEP, 0)
}[action]
if not dir then return end -- ungültige Aktion
local newPos = p + dir
if not self:isObstacle(newPos) then
self.state.position = newPos
self.agent:SetPrimaryPartCFrame(CFrame.new(newPos))
print("Neue Position:", newPos)
else
print("Hindernis im Weg!")
end
end
-- ganz simple Autopilot-Heuristik
function Simulator:autonomousStep()
local pos = self.state.position
local goal = self.state.goal
local dx = math.sign(goal.X - pos.X)
local dz = math.sign(goal.Z - pos.Z)
local try = {
(dx > 0 and "move_east") or (dx < 0 and "move_west"),
(dz > 0 and "move_south") or (dz < 0 and "move_north")
}
for _, action in ipairs(try) do
if action then
local before = self.state.position
self:executeAction(action)
if self.state.position ~= before then
return
end
end
end
-- Ausweichschritt, falls direkter Weg blockiert
for _, fallback in pairs({"move_north","move_south","move_east","move_west"}) do
local before = self.state.position
self:executeAction(fallback)
if self.state.position ~= before then
return
end
end
end
return Simulator
3. Steuer-Script „Main“
-- ServerScriptService/Main
local Simulator = require(script.Parent.Simulator)
-- Referenzen aus Workspace holen
local agent = workspace.Agent -- Model
local goal = workspace.Goal -- Part
local obstacles = workspace.Obstacles -- Folder
local sim = Simulator.new(agent, goal, obstacles)
--------------------------------------------------
-- Chat-Kommandos -------------------------------
--------------------------------------------------
local function parse(msg)
msg = msg:lower()
local map = {
["gehe nach norden"] = "move_north",
["gehe nach süden"] = "move_south",
["gehe nach osten"] = "move_east",
["gehe nach westen"] = "move_west",
}
return map[msg]
end
local autoRun = false
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message:lower() == "autonom" then
autoRun = true
player:SendNotification{Title="Autopilot",Text="KI übernimmt …"} -- optional
elseif message:lower() == "stop" then
autoRun = false
else
local action = parse(message)
if action then
sim:executeAction(action)
end
end
end)
end)
--------------------------------------------------
-- Endlosschleife für Autopilot ------------------
--------------------------------------------------
while true do
if autoRun then
sim:autonomousStep()
if (sim.state.position - sim.state.goal).Magnitude < 1 then
autoRun = false
print("Ziel erreicht!")
end
end
task.wait(0.3)
end
4. Nutzung
-
Play-Modus starten (F5).
-
Im Chat tippen:
• gehe nach Norden/Süden/Osten/Westen – manueller Schritt
• autonom – KI übernimmt und läuft bis zum Ziel
• stop – Autopilot anhalten
-
Oder direkt in Studio-Command-Bar (unten) Lua-Befehle eingeben, z.B.:
local sim = require(game.ServerScriptService.Simulator) -- nur Beispiel
5. Erweiterungen
🧠 Besseres Pathfinding
• Roblox’ PathfindingService einsetzen, statt der simplen Vier-Richtungs-Logik.
🎮 GUI-Command-Box
• ScreenGui + TextBox, dann Chat-Hook ersetzen.
📡 Multiplayer
• RemoteEvents benutzen, damit der Client nur Befehle sendet und der Server verifiziert.
Viel Erfolg beim Basteln! 💡