Menu
CoddyTech

弹跳垫

本课属于 Coddy Lua 学习旅程的“Roblox 游戏脚本编写”单元。第 19 课,共 25 课。

JumpHeight 表示角色跳跃的高度,单位是 studs。默认值为 7.2,大约相当于一个角色的身高。

旧游戏使用 JumpPower:角色离开地面时的速度。新的 Roblox 场景会忽略 JumpPower,除非启用了 UseJumpPower(在 Studio 中:StarterPlayer、CharacterUseJumpPower),所以教程中的 JumpPower 脚本不起作用时,原因就在这里。JumpHeight 更简单:这个数字就是高度。

持续一段时间的强化效果之后需要撤销。task.delay(seconds, function) 会在指定秒数后运行函数,不会暂停代码的其余部分:

humanoid.WalkSpeed = 30
task.delay(10, function()
	humanoid.WalkSpeed = 16
end)
print("Boost on")

Boost on 会立即打印出来;十秒后,速度会恢复为 16。

垫子只会更改一个属性。玩家仍需按 Space 才能跳跃。

challenge icon

挑战

中等

把蓝色踏板变成弹跳踏板,让玩家能跳上 14 英尺高的平台。

  1. 在 if 内,将 humanoid.JumpHeight 设为 20。
  2. 5 秒后,使用 task.delay 将它恢复为 7.2。

按“开始”,踩上踏板,跑向平台并跳跃:你就能落在平台顶上。然后按“检查”。

亲手试试

local pad = script.Parent

pad.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		-- 1. 让这个玩家跳到 20 studs 高
		-- 2. 5 秒后,恢复到正常的 7.2
	end
end)

Roblox 游戏脚本编写中的所有课

自己练习: Lua 在线编译器