【发布时间】:2021-11-05 14:15:46
【问题描述】:
由于某种原因,当目标目标被放置在需要跳跃才能到达我的 NPC 的某个地方时,我的 NPC 正朝着它移动,同时不断在来回移动之间切换。
代码:
local path = PathfindingService:CreatePath()
local waypoints
local currentWaypointIndex
local function followPath(destinationObject)
path:ComputeAsync(enemyNPC.HumanoidRootPart.Position, destinationObject.Position)
waypoints = {}
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
currentWaypointIndex = 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
else
error("Path not really working")
end
end
local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex += 1
if waypoints[currentWaypointIndex].Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
end
if reached and currentWaypointIndex >= #waypoints then
print("Target reached!")
animationTrack:Stop()
end
end
local function onPathBlocked(blockWaypointIndex)
if blockWaypointIndex > currentWaypointIndex then
followPath(destination)
end
end
path.Blocked:Connect(onPathBlocked)
humanoid.MoveToFinished:Connect(onWaypointReached)
followPath(destination)
(我用一些局部变量删除了代码的顶部,因为它不允许我发布整个内容而不说我的帖子主要是代码)
有人知道我做错了什么吗?
【问题讨论】:
标签: roblox