我将如何制作带有网格的建筑工具? (ROBLOX LUA)

问题描述 投票:0回答:1

我对使用lua进行编码有些陌生,目前我正在尝试制作一个游戏,其中有4个团队在一个时限内建立基础,然后进行战斗。尽管我能够做到使玩家可以构建它,但是却没有网格系统,并且所有团队都共享相同的工具。

所以我的问题是:如何制作一个“构建工具”,使玩家能够使用网格系统进行构建?我还需要以某种方式做到这一点,以便各个团队只能在各自的平台上构建。

[如果可能,还可以显示一个“鬼块”,显示玩家将要放置该块的位置。

这是到目前为止我获得的构建套件代码:

– 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
lua roblox
1个回答
0
投票

我不确定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

如果要检查它们是否在其平台上构建,则必须检查xz坐标是否在正确的范围内。而且,如果您想拥有鬼块,则必须在鼠标坐标处显示每个块,而无需实际构建它们

© www.soinside.com 2019 - 2024. All rights reserved.