我尝试制作一个寻路脚本,但它不起作用。它说“MoveTo() 不是有效的成员路径“实例””是因为 MoveTo() 不起作用,更重要的是,我有什么替代方案?
local PathFindingService = game:GetService("PathfindingService") local Agent = game.Workspace.StarterCharacter.Humanoid AgentRadius = 2 -- Settings Agent AgentHeight = 5 AgentCanJump = false AgentCanClimb = false AgentSlope = 10 AgentMaxAcceleration = 1000 AgentMaxSpeed = 16 AgentArrivalDistance = 1 -- end settings agent print(type(PathFindingService)) while true do if Agent then local destination= Vector3.new(math.random(-571,165),5.5,math.random(-495,361)) print(true) if destination then local path = PathFindingService:CreatePath() if path then print(true) start = Agent.HumanoidRootPart.Position if start then path:ComputeAsync(start, destination) path:MoveTo(Agent) --error else print (false) end end end end wait(5) end
您必须在代理人形机器人上使用
MoveTo
函数,而不是在路径变量上。例如Agent:MoveTo(Position)