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 5 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

path = game:GetService("PathfindingService"):FindPathAsync(game.Workspace.Pathfinding.Start.Position, game.Workspace.Pathfinding.Finish.Position)
waypoints = path:GetWaypoints()

for i = 2, #waypoints do
    local lastWaypoint = waypoints[i-1]
    local currentWaypoint = waypoints[i]
    print(currentWaypoint)

    local segment = Instance.new("LineHandleAdornment")
    local lastPosition = lastWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
    local currentPosition = currentWaypoint.Position + Vector3.new(0, 0.5, 0) - game.Workspace.Pathfinding.Start.Position
    local toCurrent = currentPosition - lastPosition
    local distance = toCurrent.Magnitude

    segment.CFrame = CFrame.new(lastPosition, currentPosition)
    segment.Parent = game.Workspace.Pathfinding.Start
    segment.Adornee = game.Workspace.Pathfinding.Start
    segment.Thickness = 10
    segment.Length = distance

    print(toCurrent)
    script.Parent:MoveTo(toCurrent)


    local waypointType = currentWaypoint.Action 
    if waypointType == Enum.PathWaypointAction.Jump then
        segment.Color3 = Color3.new(1, 1, 0)
    else
        segment.Color3 = Color3.new(0, 1, 0)
    end
end
0
Why is toCurrent = currentPosition - Position? Shouldn't it be just the next waypoint? thebayou 441 — 5y
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 — 5y
0
welp, It was just that Tocurrent should have been currentwaypoint.Position Dogszss 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

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

Answer this question