Roblox: 如何使 NPC 不可移动?

我正在 ROBLOX 上开发一个包含大量 NPC 的游戏。我需要一种方法来防止玩家以任何方式移动它们。我已经尝试过将 HumanoidRootPart 锚定,这样做可以让 NPC 不能移动。请问有什么方法能帮助我吗?

原文链接 https://stackoverflow.com/questions/52305790

点赞
stackoverflow用户9311837
stackoverflow用户9311837

这可以通过创建一个属性来完成。创建一个起始角色,让玩家穿戴此角色,然后修改其自定义物理属性“摩擦力”和“密度”为一个非常低的数字。

你也可以将这样的代码放在一个脚本中,例如当玩家加入时,具有“Part”类的子项的密度和摩擦力变得低。

2018-09-13 19:43:45
stackoverflow用户14551796
stackoverflow用户14551796

如果可能的话,您可以将 NPC 焊接到地面上。

这可能会起作用:

local weld = Instance.new("WeldConstraint")
weld.Part0 = part
weld.Part1 = otherPart
weld.Parent = part

这里了解更多有关焊接的信息。


如果您不需要玩家穿过所述的 NPC,则可以“取消碰撞” NPC,允许玩家穿过它但不能移动它。

local function setDescendantCollisionGroup(Descendant)
    if Descendant:IsA("BasePart") and Descendant.CanCollide then
        -- 设置碰撞组
    end
end

model.DescendantAdded:Connect(setDescendantCollisionGroup)
for _, descendant in pairs(model:GetDescendants()) do
    setDescendantCollisionGroup(descendant)
end
2020-12-04 00:19:00
stackoverflow用户16639745
stackoverflow用户16639745

尝试像这样:

    local NPC = workspace.NPC -- NPC变量 
    NPC.HumanoidRootPart.Mass = 69420

它会使NPC变得更重!

当你想让它移动时:

    local NPC = workspace.NPC -- NPC变量 
    NPC.HumanoidRootPart.Mass = 10

这会让NPC轻一些!

所以这是最终的脚本:

    local NPC = workspace.NPC -- NPC变量 
    local humanoid = NPC:WaitForChild('Humanoid') --NPC的人形对象
    local hrp = NPC.HumanoidRootPart --NPC的人形对象根部

    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内部。

2021-08-11 09:38:27