You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Roblox Studio中绑定P90的Dummy调用Humanoid:MoveTo无法移动求助

Dummy绑定P90后Humanoid:MoveTo()失效的解决办法

问题描述

在Roblox Studio中将Dummy与P90枪械模型焊接绑定后,调用Dummy的Humanoid:MoveTo()方法完全无法让其移动,尝试修改CFrame移动也无法让Humanoid正常驱动Dummy移动。

核心原因分析

  1. 硬改RootPart CFrame干扰Humanoid逻辑:代码中在RunService.Stepped事件里强制设置NPCRootPart.CFrame,这会直接覆盖Humanoid的移动控制逻辑——Humanoid本身是通过调整RootPart位置实现移动的,手动修改CFrame会导致两者冲突,打断移动。
  2. MoveTo仅调用一次,无持续追踪:chaseTarget只在进入 agro 范围时调用一次,玩家移动后Dummy不会更新目标点,自然不会持续移动。
  3. 焊接方式错误:如果枪械直接焊接到Dummy的HumanoidRootPart上,会干扰物理引擎对Humanoid移动的处理,导致无法正常移动。
  4. 变量引用可能异常:需确认npcVariables中的NPCHumanoid、NPCRootPart确实指向目标Dummy的对应部件,没有引用错误。

解决方案

1. 替换硬改CFrame的逻辑,改用Humanoid原生方法

移除直接修改RootPart CFrame的代码,用Humanoid:LookAt()实现Dummy看向目标,避免干扰移动逻辑。

2. 持续更新MoveTo目标点

在循环检查中持续调用MoveTo,确保Dummy能追踪移动的玩家,而不是只调用一次。

3. 调整焊接设置

使用WeldConstraint将枪械绑定到Dummy的Torso(或其他非RootPart部位),不要绑定HumanoidRootPart,避免影响物理交互。

4. 验证基础属性与变量引用

  • 确认Dummy的HumanoidRootPart.CanCollide为true,Humanoid.WalkSpeed大于0,Humanoid.Health大于0。
  • 打印NPCHumanoid、NPCRootPart实例,确认它们属于目标Dummy,且Humanoid.RootPart已正确设置为NPCRootPart。

修改后的关键代码示例

local function chaseTarget(targetPos)
    -- 持续更新移动目标,确保Dummy追踪玩家
    NPCHumanoid:MoveTo(targetPos)
    -- 可选:到达目标后若仍处于追踪状态,继续更新目标
    local connection
    connection = NPCHumanoid.MoveToFinished:Connect(function(reached)
        connection:Disconnect()
        if reached and npcVariables.isRunning then
            chaseTarget(targetPos)
        end
    end)
end

local function checkPositionAndFire()
    local distance = (NPCTorso.Position - torso.Position).Magnitude
    if distance < npcProperties.agroDistance then
        -- 用Humanoid原生LookAt方法,不干扰移动逻辑
        NPCHumanoid:LookAt(torso.Position)
        -- 每次检查都更新移动目标
        chaseTarget(humRootPart.Position)
        
        fireP90()
        
    else
        npcVariables.isRunning = false
        -- 停止移动,让Dummy留在原地
        NPCHumanoid:MoveTo(NPCTorso.Position)
    end
end

注意:原代码中RunService.Stepped的连接会重复创建(每次checkPositionAndFire都会新增一个连接),会导致性能问题,必须移除这部分逻辑,改用上述的Humanoid:LookAt。

内容的提问来源于stack exchange,提问作者Paysmon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 10:20:05