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

Pathfinding Issue, NPC refusing to walk path?

Asked by 6 years ago

Greetings, Thanks for taking a look into my issue.

I made a pathfinding script in which I told an NPC to follow a path. (called Jake) The path gets correctly created and I made it so a line shows how the path goes. It's just that Jake refuses to follow the line and walks off on his own.

Here is the code, Any help is appriciated

01path = game:GetService("PathfindingService"):FindPathAsync(game.Workspace.Pathfinding.Start.Position, game.Workspace.Pathfinding.Finish.Position)
02waypoints = path:GetWaypoints()
03 
04for i = 2, #waypoints do
05    local lastWaypoint = waypoints[i-1]
06    local currentWaypoint = waypoints[i]
07    print(currentWaypoint)
08 
09    local segment = Instance.new("LineHandleAdornment")
10    local lastPosition = lastWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
11    local currentPosition = currentWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
12    local toCurrent = currentPosition - lastPosition
13    local distance = toCurrent.Magnitude
14 
15    segment.CFrame = CFrame.new(lastPosition, currentPosition)
View all 31 lines...
0
Why is toCurrent = currentPosition - Position? Shouldn't it be just the next waypoint? thebayou 441 — 6y
0
Like 'thebayou' said but toCurrent should equal currentWaypoint.Position. also I would use a humanoid for the moveTo method or at least lerp the CFrame of the model to the current waypoint Impacthills 223 — 6y
0
welp, It was just that Tocurrent should have been currentwaypoint.Position Dogszss 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

welp, It was just that Tocurrent should have been currentwaypoint.Position

0
Like I said but okay. Impacthills 223 — 6y
Ad

Answer this question