منصات الارتداد
الدرس 9 من 18 في دورة لعبة Roblox: البرج اللانهائي على Coddy.
تحتوي مرحلة Bounce على منصة خضراء تحمل الوسم Bounce، أسفل حافة مرتفعة جدًا بحيث لا يمكن القفز إليها. يجب أن يؤدي الهبوط على المنصة إلى قذفك إلى أعلاها.
تتحرك الشخصية باستخدام HumanoidRootPart، وهو الجزء غير المرئي في وسطها. اضبط AssemblyLinearVelocity لذلك الجزء، وستطير الشخصية في ذلك الاتجاه، ثم تعيدها الجاذبية إلى الأسفل:
root.AssemblyLinearVelocity = Vector3.new(0, 60, 0) -- 60 وحدة قياس في الثانية، إلى الأعلى مباشرةًتعطيك Touched الطرف الذي اصطدم بالمنصة، ويكون عادةً ساقًا. والجزء الأب له هو الشخصية التي تحتوي على HumanoidRootPart.
التحدي
متوسط- اكتب
bounce(hit): إذا كان نموذج اللاعب الذي لمسها يحتوي علىHumanoidRootPart، فاضبطAssemblyLinearVelocityالخاص بها علىVector3.new(0, Settings.BouncePower, 0). - في
setupStage، اربط حدث Touched لكل جزء يحمل الوسمBounceبها.
اضغط على Play، اهبط على منصة القفز وتوجّه إلى الحافة. ثم اضغط على Check.
جرّب بنفسك
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
-- تدور العناصر الدوّارة قليلًا في كل إطار
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()
يتضمن هذا الدرس اختبارًا قصيرًا. ابدأ الدرس للإجابة عليه وتتبّع تقدمك.