I’m making a NPC that follows you but for some reason he has a small brain. He wont jump over obstacles, he wont go around them, and sometimes he gets creative mode and flys around (No clue how). I would like some help because I really want this working by the end of the day. Thanks for your help!
Video:
https://gyazo.com/b7c7e2c9ff1d6a91d0eaf4fbb301f837
Code:
local parent = script.Parent
local pathfinding_service = game:GetService("PathfindingService")
while wait() do
if not parent.Configuration.Owner.Value then return end
local path = pathfinding_service:CreatePath()
local playerCharacter = parent.Configuration.Owner.Value.Character
local distance = (parent.PrimaryPart.Position - playerCharacter.PrimaryPart.Position).Magnitude
if distance > 10 then
path:ComputeAsync(parent.HumanoidRootPart.Position, playerCharacter.PrimaryPart.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
parent.Humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
local distance = (parent.PrimaryPart.Position - waypoint.Position).Magnitude
local distance_from_player = (parent.PrimaryPart.Position - playerCharacter.PrimaryPart.Position).Magnitude
if distance_from_player < 10 then
parent.Humanoid:MoveTo((parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3)).p)
break
end
end
end
end