Lua 如何使用网格制作建筑工具?(罗布罗克斯·卢阿)
我对lua编码有点陌生,目前我正在尝试制作一个游戏,其中4个团队在时间限制内建立一个基地,然后战斗。虽然我能够做到让玩家可以构建,但没有网格系统,所有团队共享同一个工具 所以我的问题是:如何制作一个“构建工具”,使玩家能够使用网格系统进行构建?我还需要设法做到这一点,以便各个团队只能在各自的平台上进行构建 如果可能的话,还有一个“鬼挡”,显示玩家将要放置挡块的位置 这是我到目前为止获得的建筑工具包代码:Lua 如何使用网格制作建筑工具?(罗布罗克斯·卢阿),lua,roblox,Lua,Roblox,我对lua编码有点陌生,目前我正在尝试制作一个游戏,其中4个团队在时间限制内建立一个基地,然后战斗。虽然我能够做到让玩家可以构建,但没有网格系统,所有团队共享同一个工具 所以我的问题是:如何制作一个“构建工具”,使玩家能够使用网格系统进行构建?我还需要设法做到这一点,以便各个团队只能在各自的平台上进行构建 如果可能的话,还有一个“鬼挡”,显示玩家将要放置挡块的位置 这是我到目前为止获得的建筑工具包代码: -- all of this is in a localscript inside of t
-- all of this is in a localscript inside of the hammer tool
local players = game:GetService("Players")
local hammer = script.Parent -- the hammer tool that will make the player know they are in “building mode”
local player = game.Players.LocalPlayer
local mouse = player:GetMouse() -- get the mouse from the player
local function placeBlock(Part)
local position = mouse.Hit.p -- the position of the mouse so i can place blocks there
local buildingBrickRed = Instance.new("Part") -- creates a part that the player will place
buildingBrickRed.Parent = workspace
buildingBrickRed.BrickColor = BrickColor.new("Really red") -- makes the brick red
buildingBrickRed.Size = Vector3.new(5, 5, 5) -- sets the size of the block
buildingBrickRed.CFrame = CFrame.new(position) -- sets the position of the block to be where the mouse is
end
hammer.Activated:Connect(placeBlock) -- connects to the function when the player activates the tool
我不确定Roblox的编码是如何工作的,但是对于网格,您可以通过将鼠标坐标除以砖块大小,舍入该值并再次相乘来更改鼠标坐标(假设这也是一个3D向量)
function griddify(coordinate)
return math.floor(coordinate / 5) * 5
end
print(griddify(31)) --> 30
print(griddify(31.4)) --> 30
print(griddify(3141)) --> 3140
如果您想检查他们是否在平台上建造,您必须检查x和z坐标是否在正确的范围内。
如果你想拥有幻影块,你必须在鼠标坐标上显示每个块,而不是实际构建它们