Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I fix this AI standing still when it shouldnt? Real All

Asked by 5 years ago

So in my game, I have AI workers similar to Retail Tycoon. So I have this AI module that uses pathfinding service to go to the waypoints it sets. So i found out that the character tries to go to other waypoints they didn't even reach yet which makes them go into walls. So i made a Magnitude check to make sure if the ai is close the waypoint then go to the next, but if another AI moves the original AI in any other way it just stand still. How would i tackle this issue?

local module = {}
    function module.RunAI(Goal,Character)
        math.randomseed(tick())
        math.random()
        local pfs = game:GetService("PathfindingService")
        local Waypoints = Goal:GetChildren()
        while true do 
            local Waypoint = Waypoints[math.random(1,#Waypoints)] 
            local FoundPath = pfs:FindPathAsync(Character.HumanoidRootPart.CFrame.p,Waypoint.CFrame.p)
            local Path = FoundPath:GetWaypoints()
            for i = 1,#Path do 
                if Path[i].Action == Enum.PathWaypointAction.Jump then
                    Character.Humanoid.Jump = true
                else
                    repeat wait() until Path[i].Position.Magnitude - Character.HumanoidRootPart.CFrame.p.Magnitude < 4
                    Character.Humanoid:MoveTo(Path[i].Position)
                end
            end
            wait(math.random(2,8))
        end
    end
return module

0
When you use . Instead of : , the first parameter is always the table/object. User#19524 175 — 5y
0
On what line your talking about @incapz NumbersInBinary 33 — 5y
0
line 2, also i don't think so? thebayou 441 — 5y
0
That isnt the issue re read the questioni asked. NumbersInBinary 33 — 5y
View all comments (2 more)
0
why are you making it go to a random waypoint each time? (unrelated, but just curious) thebayou 441 — 5y
0
i want the character to go to its work place sit then get up to get papers or to get some drinks. Make it look dynamic NumbersInBinary 33 — 5y

1 answer

Log in to vote
0
Answered by
thebayou 441 Moderation Voter
5 years ago

I believe the culprit is line 15

repeat wait() until Path[i].Position.Magnitude - Character.HumanoidRootPart.CFrame.p.Magnitude < 4

This causes the AI to keep on waiting, and waiting. I think you meant to put the line under it in front of it?

Ad

Answer this question