-
What do you want to achieve? Keep it simple and clear!
I want to configure my current code so that my NPC’s will jump down from a higher point to get to it’s target. -
What is the issue? Include screenshots / videos if possible!
My zombie NPC’s don’t walk down if it’s target Y value is lower than it’s Y value -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried making a simple :moveto(target) script that runs for a second when it detects that the target’s Y value is lower than the zombie. This worked for a bit, however the NPC will then get stuck behind walls since it isn’t computing a route.
Here is the portion of the code giving me issues:
function pathToTarget(zombie)
local path = game:GetService("PathfindingService"):CreatePath({AgentRadius = 1,AgentHeight = 5,AgentCanJump = true,AgentCanClimb = true})
path:ComputeAsync(zombie.root.Position,zombie.target.Position)
local currentTarget = zombie.target
local waypoints = path:GetWaypoints()
for i, v in pairs(waypoints) do
-- If the NPC is higher than the target:
if zombie.target ~= nil then
if zombie.target.Position.y + 2.4 < zombie.root.Position.y then
zombie.human:MoveTo(zombie.target.Position)
break
end
end
--If there are two or more waypoints then:
if waypoints and waypoints[2] then
local data = waypoints[2]
zombie.human:MoveTo(data.Position)
if v.Action == Enum.PathWaypointAction.Jump then
zombie.human:MoveTo(v.Position)
if checkDist(zombie.root,v) < 7 then
zombie.human.Jump = true
end
end
end
end
end