【问题标题】:The NPC follows the part but when i go near the NPC they leave the part and start going to random directionsNPC 跟随该部分,但是当我靠近 NPC 时,他们离开该部分并开始向随机方向前进
【发布时间】:2021-03-30 21:18:02
【问题描述】:

所以当我点击 npc 时,我试图让 npc 移动到一个零件,当我点击它时,一切似乎都很好,直到我靠近 npc,然后它离开了零件并开始随机移动方向。有什么问题吗?

脚本:

    local value = script.Parent.FollowSurvivor
local value2 = workspace.Values.MoveToValue

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 1000
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            temp = temp2:findFirstChild("Torso")
            human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end

while true do
    wait(0.5)
    local target = findNearestTorso(script.Parent.Torso.Position)
    if target ~= nil then
        if value.Value == true then
            script.Parent.Zombie:MoveTo(target.Position, target)
        end
        if value.Value == false then
            script.Parent.Zombie:MoveTo(workspace.MoveToPart.Position)
        end
    end
    end

【问题讨论】:

  • 当你靠近时,你的僵尸会互相撞到吗?
  • 不,当我靠近它们时,它们会随机进入方向

标签: roblox


【解决方案1】:

此脚本获取最近的类人生物并朝它走去。当你走到它旁边时,它发现了你的类人生物并开始跟随你。

【讨论】:

  • 谢谢,但我停止了工作,但还是谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-07
  • 2016-04-12
相关资源
最近更新 更多