我目前正在开发一款包含大量NPC的游戏,我需要一种方法来让玩家不能以任何方式移动它们。我试过锚定HumanoidRootPart,它起作用了,但它使NPC无法移动。
有人能帮上忙吗?
发布于 2020-12-04 08:19:01
如果可能的话,你可以把NPC焊接到地面上。
这可能是可行的:
local weld = Instance.new("WeldConstraint")
weld.Part0 = part
weld.Part1 = otherPart
weld.Parent = part这里有更多关于焊接的信息here。
如果你不需要玩家通过这些NPC,你可以“解开”NPC,允许玩家通过它但不能移动它。
local function setDescendantCollisionGroup(Descendant)
if Descendant:IsA("BasePart") and Descendant.CanCollide then
-- set collision group
end
end
model.DescendantAdded:Connect(setDescendantCollisionGroup)
for _, descendant in pairs(model:GetDescendants()) do
setDescendantCollisionGroup(descendant)
end发布于 2018-09-14 03:43:45
这应该能够使用属性来完成。创建一个首发角色,让玩家佩戴这个角色,然后修改它的自定义物理属性“摩擦力”,“密度”到一个非常低的数字。
你也应该能够把这样的东西放在脚本中,比如当一个玩家加入时,带有类"Part“的孩子的密度和摩擦力都很低。
发布于 2021-08-11 09:38:27
尝试如下所示:
local NPC = workspace.NPC --The NPC variable
NPC.HumanoidRootPart.Mass = 69420这应该会让全国人民代表大会变得更重!
当你想让它移动的时候:
local NPC = workspace.NPC --The NPC variable
NPC.HumanoidRootPart.Mass = 10这将使全国人民代表大会更轻!
所以这是最终的脚本:
local NPC = workspace.NPC --The NPC variable
local humanoid = NPC:WaitForChild('Humanoid') --NPC's humanoid
local hrp = NPC.HumanoidRootPart --NPC's HumanoidRootPart
local mass1 = 69420
local mass2 = 10
humanoid.Running:Connect(function(speed)
if speed > 0.001 then
hrp.Mass = mass2
else
hrp.Mass = mass1
end
end)确保在ServerScript中编写该代码!
如果需要,可以将脚本放入NPC中。
https://stackoverflow.com/questions/52305790
复制相似问题