When it computes the path it doesn’t sense that there is a part, so the waypoint is in the part making the pet glide through the part like a ghost instead of going on top of it. The white balls represent the waypoints.
local PathfindingService = game:GetService("PathfindingService")
local waypoints
local function followPath(destinationObject, path, HRP)
-- Compute and check the path
path:ComputeAsync(Pet.Sphere.Position, destinationObject.Position)
-- Empty waypoints table after each new path coputation
waypoints = {}
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start pet walking
waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(1,1,1)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
end
for _, waypoint in pairs(waypoints) do
local propertyTable = {
Position = waypoint.Position + (Vector3.new(0,0.7,0)) --+ (Vector3.new(humanoid.Size))
}
local tween = tweenService:Create(Pet.Sphere.BodyPosition, tweeningInformation, propertyTable)
tween:Play()
end
Pet.Sphere.BodyGyro.CFrame = CFrame.new(Pet.Sphere.Position, HRP.Position)
end
end
while true do
local Character = plr
local HRP = Character:WaitForChild('HumanoidRootPart')
local CurrentPosition = HRP.Position
local DistanceTravelled = (CurrentPosition - LastPosition).Magnitude
if DistanceTravelled >= 4 and DistanceTravelled <= 50 then
local destination = HRP.CFrame:ToWorldSpace(CFrame.new(-3,0,0))--define the destination
LastPosition = CurrentPosition
local path = PathfindingService:CreatePath()--Create a path
followPath(destination, path, HRP)
I took out parts of the code that don’t have to do with pathfinding to make it shorter.
Hi!, can you help me? I have the exact same problem, but with the entire map, the NPC goes straight to the point, and ignores the parts of the map, except the terrain. pls help me!