המסוע
שיעור 3 מתוך 18 בקורס משחק Roblox: טייקון מפעל של Coddy.
עפרה שמצטברת מתחת למכונה להוצאת עפרה לא מרוויחה כלום. היא צריכה להגיע לאספן, ומסוע מעביר אותה לשם.
ב-Roblox מסוע הוא חלק מעוגן עם מהירות. הגדרת AssemblyLinearVelocity בחלק מעוגן לא מזיזה דבר בפני עצמה, אבל כל מה שנמצא עליו נסחף במהירות הזאת, כולל שחקנים:
conveyor.AssemblyLinearVelocity = Vector3.new(8, 0, 0)הווקטור מציין לאיזה כיוון ובאיזו מהירות: 8 studs לשנייה לאורך ציר X. המהירות מוגדרת ב-Settings.BeltSpeed.
אתגר
קלהגדר את tycoon.Conveyor.AssemblyLinearVelocity ל־Settings.BeltSpeed studs לשנייה לאורך ציר X.
לחץ על Play וצפה בעפרה נוסעת (וקפוץ בעצמך על המסוע). לאחר מכן לחץ על Check.
נסו בעצמכם
local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)
local tycoon = workspace.Tycoon
print("Ore is worth " .. Settings.OreValue .. " Cash")
-- כל שחקן מקבל Cash בטבלת המובילים
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
end)
-- Ore: חלק קטן ששווה Cash, שנופל מתחת למתקן ההפלה
local function dropOre(dropper)
local ore = Instance.new("Part")
ore.Name = "Ore"
ore.Size = Vector3.new(1, 1, 1)
ore.Color = Color3.fromRGB(150, 150, 160)
ore.Position = dropper.Position - Vector3.new(0, 2.5, 0)
ore:SetAttribute("Value", Settings.OreValue)
ore.Parent = workspace
end
local function startDropper(dropper)
task.spawn(function()
while dropper:IsDescendantOf(workspace) do
dropOre(dropper)
task.wait(Settings.DropInterval)
end
end)
end
startDropper(tycoon.Dropper)
השיעור הזה כולל חידון קצר. התחילו את השיעור כדי לענות עליו ולעקוב אחרי ההתקדמות.