【问题标题】:Roblox: Make an NPC immovable?Roblox:让 NPC 不动?
【发布时间】:2019-02-17 17:18:57
【问题描述】:

我目前正在 ROBLOX 上开发一款包含大量 NPC 的游戏。我需要一种方法让玩家无法以任何方式移动它们。我已经尝试锚定 HumanoidRootPart,并且成功了,但它使 NPC 无法移动。

谁能帮忙?

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    如果可能的话,你可以将 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
    

    【讨论】:

      【解决方案2】:

      这应该可以使用属性来完成。创建一个初始角色,让玩家穿上这个角色,然后将其自定义物理属性“摩擦”、“密度”修改为非常低的数字。

      您还应该能够将此类放入脚本中,例如当玩家加入时,具有“Part”类的孩子的密度和摩擦力较低。

      【讨论】:

      • 编辑:我解决了这个问题!起初,我以为您是要更改 NPC 的 CustomPhysicalProperties。谢谢您的帮助! @Shyvha
      【解决方案3】:

      试试这样的:

          local NPC = workspace.NPC --The NPC variable
          NPC.HumanoidRootPart.Mass = 69420
      

      它应该会使 NPC 更重!
      当您希望它移动时:

          local NPC = workspace.NPC --The NPC variable
          NPC.HumanoidRootPart.Mass = 10
      

      这将使 NPC 更轻!
      所以这是最终的脚本:

          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 中。

      【讨论】:

        猜你喜欢
        • 2018-12-16
        • 2021-06-24
        • 1970-01-01
        • 2021-12-26
        • 2021-08-12
        • 2019-08-21
        • 2021-07-27
        • 1970-01-01
        • 2020-08-07
        相关资源
        最近更新 更多