Problem with learning pathfinding

Yo! u probably have already seem me in this forum
Basically, from a old post i made somebody told me to use pathfinding to detect players and magnitude to do what i want when its close to the player

But i find it really hard working with pathfinding and all tutorials i see i cant understand
Could anyone explain better for me how do i use pathfinding and magnitude to make the AI functions?

(The AI magnitude functions are the rake functions,so like the rake get faster when its close to the player and screen flashing, and a song when rake is close)

Hope i could explain well my problems
it would be cool if anyone could explain better to me

I would recommend watching Advanced Roblox Scripting Tutorial #21 - Pathfinding (Beginner to Pro 2019) - YouTube for a pathfinding tutorial, as I could understand it quite easily. But basically, it finds the fastest route from one point to another. For example:

local PathfindingService = game:GetService("PathfindingService") -- Getting the service
local path = PathfindingService:CreatePath() -- Creating a new path
path:ComputeAsync(pos1, pos2)  -- Computing the waypoints
local waypoints = path:GetWaypoints() -- Get all the waypoints

That is in essence how pathfinding works, and if you wanted to move a character then you can loop through the waypoints table and move the character to each waypoint

for _, waypoint in pairs(waypoints) do
     Character.Humanoid:MoveTo(waypoint.Position) -- Moves the character to the waypoint
     Character.Humanoid.MoveToFinished:Wait()  -- Waits until the character is done moving so that it doesn't try to move to the next waypoint before it's finished with its current one.
end

And magnitude can be used to find a distance between one object and another. (Tutorial I used: Advanced Roblox Scripting Tutorial #22 - Magnitude (Distance) [Beginner to Pro 2019] - YouTube )
Example:

local part1 = workspace.Part1
local part2 = workspace.Part2

local distance = (Part1.Position - Part2.Position).Magnitude 
print(distance)

If the distance is negative, you can also do math.abs(distance) to make it positive.

Hopefully that helps.

1 Like

yo thx, i will see these rn

Message has no 30 letters