Menu
CoddyTech

משטחי קפיצה

שיעור 10 מתוך 21 בקורס משחק Roblox: מגדל אינסופי של Coddy.

בשלב Bounce יש משטח ירוק שמתויג בתור Bounce, מתחת למדף גבוה מדי מכדי לקפוץ אליו. נחיתה על המשטח אמורה להעיף אותך למעלה, אל המדף.

דמות נעה באמצעות HumanoidRootPart שלה, החלק הבלתי נראה שבמרכזה. הגדר את AssemblyLinearVelocity של החלק הזה, והדמות תעוף בכיוון הזה, ואז כוח הכבידה ימשוך אותה למטה:

root.AssemblyLinearVelocity = Vector3.new(0, 60, 0) -- 60 סטאדים בשנייה, ישר למעלה

Touched נותן לך את האיבר שפגע במשטח, בדרך כלל רגל. ההורה שלו הוא הדמות, שמכילה את HumanoidRootPart.

challenge icon

אתגר

בינוני

גרום למשטח הירוק להעיף אותך אל המדף.

  1. כתוב את bounce(hit): אם יש ל-hit.Parent רכיב HumanoidRootPart, הגדר את AssemblyLinearVelocity שלו ל-Vector3.new(0, Settings.BouncePower, 0).
  2. בתוך setupStage, חבר את האירוע Touched של כל חלק שמתויג Bounce לפונקציה.

לחץ על "שחק" ודרוך על המשטח הירוק: הוא יעיף אותך למעלה לצד המדף. לאחר מכן לחץ על "בדיקה".

נסו בעצמכם

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Settings = require(game.ReplicatedStorage.Settings)

local stages = ServerStorage.Stages
local tower = nil

print("Each tower has " .. Settings.StageCount .. " stages")

-- כל שחקן מקבל Wins בטבלת המובילים
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
end)

-- כל דבר שמסומן בתג Kill מסיים חיים
local function killOnTouch(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		humanoid.Health = 0
	end
end

-- מדרגה נעלמת דוהה זמן קצר אחרי שמישהו נוחת עליה, ואז חוזרת
local function makeVanish(part)
	part.Touched:Connect(function(hit)
		if part:GetAttribute("Gone") or not hit.Parent:FindFirstChild("Humanoid") then
			return
		end
		part:SetAttribute("Gone", true)
		task.wait(Settings.VanishDelay)
		part.Transparency = 0.8
		part.CanCollide = false
		task.wait(Settings.VanishTime)
		part.Transparency = 0
		part.CanCollide = true
		part:SetAttribute("Gone", nil)
	end)
end

-- לייזר מחליק עד להיסט Slide שלו ובחזרה, ללא הפסקה
local function makeSlide(part)
	local info = TweenInfo.new(Settings.SlideTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
	local goal = { Position = part.Position + part:GetAttribute("Slide") }
	TweenService:Create(part, info, goal):Play()
end

-- שיעור 10: Bounce Pads מופיע כאן

-- הספינרים מסתובבים מעט בכל פריים
RunService.Heartbeat:Connect(function(dt)
	for _, spinner in CollectionService:GetTagged("Spinner") do
		if spinner:IsDescendantOf(workspace) then
			spinner:PivotTo(spinner:GetPivot() * CFrame.Angles(0, math.rad(Settings.SpinSpeed) * dt, 0))
		end
	end
end)

-- הפעל כל מכשול בשלב לפי התגים שלו
local function setupStage(stage)
	for _, part in stage:GetDescendants() do
		if part:HasTag("Kill") then
			part.Touched:Connect(killOnTouch)
		end
		if part:HasTag("Vanish") then
			makeVanish(part)
		end
		if part:HasTag("Conveyor") then
			part.AssemblyLinearVelocity = part.CFrame.LookVector * Settings.BeltSpeed
		end
		if part:HasTag("Slider") then
			makeSlide(part)
		end
	end
end

-- שלב כלשהו, באקראי
local function pickStage()
	local all = stages:GetChildren()
	return all[math.random(1, #all)]
end

-- הנח עותק של מודל על גבי המגדל; מחזיר את העותק ואת הגובה החדש של המגדל
local function stack(template, bottom)
	local copy = template:Clone()
	local box, size = copy:GetBoundingBox()
	local lift = bottom - (box.Position.Y - size.Y / 2)
	copy:PivotTo(copy:GetPivot() + Vector3.new(0, lift, 0))
	copy.Parent = tower
	return copy, bottom + size.Y
end

-- בנה מגדל אקראי חדש, מלמטה למעלה
local function buildTower()
	tower = Instance.new("Model")
	tower.Name = "Tower"
	tower.Parent = workspace
	local top = 0
	for i = 1, Settings.StageCount do
		local stage, newTop = stack(pickStage(), top)
		top = newTop
		setupStage(stage)
	end
	stack(ServerStorage.Finish, top)
end

buildTower()

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

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