Menu
CoddyTech

המסוע

שיעור 3 מתוך 22 בקורס משחק Roblox: איל מפעל של Coddy.

עפרה שמצטברת מתחת למתקן ההפלה לא מרוויחה כלום. היא צריכה להגיע לאספן, ומסוע מוביל אותה לשם.

ב-Roblox, מסוע הוא חלק מעוגן שיש לו מהירות. הגדרת AssemblyLinearVelocity בחלק מעוגן לא מזיזה שום דבר בפני עצמה, אבל כל מה שנח עליו נישא יחד איתו במהירות הזאת, כולל שחקנים:

tycoon.Conveyor.AssemblyLinearVelocity = Vector3.new(12, 0, 0)

הווקטור מציין את הכיוון ואת המהירות: 12 studs לשנייה לאורך ציר X. מהירות המשחק שלך נמצאת ב-Settings.BeltSpeed.

challenge icon

אתגר

קל

הפעל את המסוע כדי שיסיע את העפרה אל האספן.

  1. מתחת לקוד של הטפטפת, הגדר את tycoon.Conveyor.AssemblyLinearVelocity.
  2. הגדר אותו ל־Vector3.new(Settings.BeltSpeed, 0, 0): ‏BeltSpeed יחידות בשנייה לאורך ציר X.

לחץ על "שחק": העפרה נעה על המסוע אל הבלוק הירוק, וגם אתה אם תעלה עליו. לאחר מכן לחץ על "בדיקה".

נסו בעצמכם

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, שנופל מתחת ל-dropper
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)

-- שיעור 3: ה-Conveyor ממוקם כאן

כל השיעורים ביחידה משחק Roblox: איל מפעל

תרגלו בעצמכם: Roblox אונליין