#AI Pathfinding

123 messages · Page 1 of 1 (latest)

wispy socket
#

I want to learn AI pathfinding but i noticed there isnt really any great tutorial anywhere and was wondering if anyone can teach me some stuff about it.

#

i want to make a horror game where an AI will chase you

timber mica
#

maybe contact @celest parcel ?

#

i think they know something about that

smoky wave
#
local pfs = game:GetService('PathfindingService')
local bot = workspace:WaitForChild('bot')
local jumpscareremote = game.ReplicatedStorage.jumpscare
local radius = bot.hitbox

bot.PrimaryPart:SetNetworkOwner(nil)

local path : Path = pfs:CreatePath({
    AgentRadius = 5,
    AgentHeight = 5,
    AgentCanJump = false,
})

local debounce = false

radius.Touched:Connect(function()end)

game.Players.PlayerAdded:Connect(function(plr)
    local connection
    
    plr.CharacterAdded:Connect(function(char)    
        local hrp = char:WaitForChild('HumanoidRootPart')
        
        hrp.Touched:Connect(function(part)
            if part.Parent:FindFirstChild('Humanoid') and part ~= radius then
                if debounce then return end
                debounce = true
                char:FindFirstChild('Humanoid').Health = 0
                jumpscareremote:FireClient(plr)
                task.wait(5)
                debounce = false
            end
        end)

        if connection then
            task.cancel(connection)
        end

        connection = task.spawn(function()
            while task.wait() do
                local partgoto

                path:ComputeAsync(bot.HumanoidRootPart.Position,hrp.Position)

                if path.Status == Enum.PathStatus.Success then
                    for i,v in ipairs(path:GetWaypoints()) do
                        bot.Humanoid:MoveTo(v.Position)
                        bot.Humanoid.MoveToFinished:Wait()
                    end
                end
            end
        end)
    end)
end)
#

there

#

@wispy socket

wispy socket
#

bro i need some explaining not just a script ;-;

#

its like a rocket-scientist trainee asking for help and you just give him a freaking rocket and tell him "you are welcome"

#

@smoky wave

smoky wave
#

There are TONS of tutorials on online

#

If you can’t understand a tutorial from AlvinBlox or DevKing, then you are too ahead of your skill

wispy socket
#

but i get what you mean

smoky wave
#

TheDevKing does

wispy socket
#

alr

wispy socket
smoky wave
#

THAT is literally how anyone would do pathfinding

wispy socket
#

whats wrong here then

smoky wave
#

You’re not meant to out anything inside :Wait

#

And pair should be pairs

#

Actually change that to ipairs

wispy socket
#

whats wrong on line 13 tho

smoky wave
#

I just told you bruh

#

You are not meant to out anything inside of :Wait

wispy socket
#

thats how he did it in the video tho

smoky wave
#

That line is meant to wait until it moves to the destination

#

No he didn’t

#

I’ve seen it

wispy socket
#

;-;

smoky wave
#

Remove it

wispy socket
#

a screenshot from the video

smoky wave
#

Remove it

#

I have no idea why he put a argument in there

#

Then remove the last line too

#

You should have up to line 13

wispy socket
#

so im removing MoveToFinished?

smoky wave
#

No

#

Don’t put in that last line in your gyazo screenshot

wispy socket
#

yeah i didnt

#

but what do i change on line 13

smoky wave
#

Remove the 2

wispy socket
#

alr

#

still doesnt work

smoky wave
#

What does it say

wispy socket
#

Workspace.Dummy.AI:13: Expected '(', '{' or <string> when parsing function call, got ':' - Studio - AI:13

smoky wave
#

Oh I see

#

You used a column in line 13

wispy socket
#

ye

#

it needs a string?

smoky wave
#

It’s human.MoveToFinished:Wait()

#

No

#

Listen

#

You put human:MoveToFinsihed:Wait()

#

See the difference?

wispy socket
#

yeah i do

smoky wave
#

Yeah so change it

wispy socket
#

lemme run it

#

another error

smoky wave
#

In line 11,

#

Change “for I, waypoints” to “for I, waypoint”

wispy socket
#

yeah i fixed it

#

mb

smoky wave
#

Make sure you read it carefully

wispy socket
#

it still doesnt work tho

wispy socket
#

doesnt work still

smoky wave
wispy socket
#

no errors

#

the AI doesnt move

smoky wave
#

Do me favour,

timber mica
#

i hate coding ai i feel you

smoky wave
#

Add a line and print “path.Status”

wispy socket
#

it didnt print anythin

smoky wave
#

Where did you print it

wispy socket
#

i just wrote print(path.Status)

smoky wave
#

I said where

wispy socket
#

line 17

smoky wave
#

Show me your entire script

wispy socket
smoky wave
#

Put it before the for loop

wispy socket
#

aight

#

it says Enum.PathStatus.Success

smoky wave
#

Wait hold on

smoky wave
#

In line 13

wispy socket
#

same result

smoky wave
#

Remove it anyway you don’t need it

wispy socket
#

maybe theres something wrong with my dummy

timber mica
#

ba du bah

smoky wave
#

Is your model unanchored?

wispy socket
#

ye

smoky wave
timber mica
#

ask the squidward killer games dev

smoky wave
#

It’s not gonna fix it but do it anyway

wispy socket
#

ehm

#

it fixed it

timber mica
#

LOL

wispy socket
#

lmao

timber mica
#

me when accidental fix

smoky wave
#

So it works?

wispy socket
#

may i ask whats the difference between pairs and ipairs

#

yeah

#

i was told to use pairs on both arrays and dictionaries

smoky wave
#

ipairs os guaranteed to iterate in order

timber mica
#

💯💯💯

smoky wave
#

Use pairs for when iterating in dictionaries

wispy socket
smoky wave
#

But in most cases you should use ipairs because it’s faster

#

alr

#

Say you have an array with 1, 2, 3, 4 and so on

wispy socket
#

ye

smoky wave
#

If you use pairs,

#

It can sometimes iterate in a random order

#

But using ipairs iterates in order so that it will go, 1, 2 3, 4

#

It’s also faster too

wispy socket
#

oh i didnt know that