Introducing the Pathfinding Links for NPCs Beta

Hello AI developers,

Introducing PathfindingLinks

PathfindingLinks provide developers with the ability to connect two locations that are otherwise unconnected. For example:

  • Custom action like using boat: An NPC can pathfind through complex objects that connect distant parts of the map. Let’s say in a treasure hunt experience an NPC without swimming capabilities has two options to reach the treasure located on a different island. One option is to take a long walk and reach the treasure using the bridge connecting the island and another option is to use a boat to reach the destination island as shown in the figure below. Pathfinding is now capable of generating a path that would use the boat.

  • Local teleport: Often developers want to teleport NPCs to a new location but our pathfinding system is not able to find the path as these two locations are unconnected. Pathfinding links connect these two locations together and have pathfinding come up with the path.

  • Custom Jumps: Let’s say in the experience there is a river and the developer wants to provide the capabilities for a specific NPC in the experience to cross the river in just a single jump. This can be achieved using pathfinding links.


New Instance: PathfindingLink

Properties

  • Instance attachment 0: The attachment the link originates from.

  • Instance attachment 1: The attachment the link ends at.

  • bool IsBidirectional: Specifies the link directionality. Default True.

  • string Label: The name of the navigation area used for the link. It is used to identify the action to take in setting the cost for the link.

How to create a pathfinding link:

Developers will create a pathfinding link and assign the source and destination attachment. They can override the default for bidirectional. They will also specify the label. For more about labels refer to PathfindingModifier Label.

For example, using the above scenario of a treasure hunt experience, if we want to connect the two islands together, we can create two attachments, one on each island, and then create a pathfinding link distance as shown below:

local link = Instance.new("PathfindingLink", model)
link.Attachment0 = … -- starting point of the link
link.Attachment1 = … -- end point of the link
link.IsBidirectional = false
link.Label = "Boat"
local path = PathfindingService:CreatePath{
    Costs = {
        Boat = 1,
        Bridge = math.huge,
    }
}

path:ComputeAsync(from, to)

New PathWaypoint Properties:

  • string Label: The name of the navigation area inside or on top of the part’s volume. Returning the label will help developers decide the custom action they want to take based on the link. For automatic jump links we will set Label = Jump

  • New value in PathWaypointAction.Action

  • PathWaypointAction.Custom: This value will be set in PathWaypoint.Action for links created by the user. Automatically generated jump links will continue to populate the Jump action.

For more details please refer to PathfindingLink.


How to use a Follow Path containing Pathfinding Links

Custom Actions: Using the same example from above, we can make NPC use a boat as follows:

if path.Status == Enum.PathStatus.Success then
  -- Get path waypoints
  local waypoints = path:GetWaypoints()
  -- Loop through waypoints
  for _, waypoint in pairs(waypoints) do
    if waypoint.Label == "Boat" then
       useBoat()
    elseif waypoint.Label = "Jump" then
      --- Jump to the next point
    else
      --- Walk to the next point
    end
  end
end

function useBoat()
  zombie.Humanoid:MoveTo(seatPosition)
  humanoid.MoveToFinished:Connect(function(reached)
	if reached then
	  workspace.Boat.BoatSeat:Sit(humanoid)
	  if humanoid.Sit then
	    local bodyPosition = Instance.new("AlignPosition")
	    bodyPosition.Position = workspace.LandingDock.Position
	    bodyPosition.Attachment0 = workspace.Boat.CylindricalAttachment1
	    bodyPosition.Attachment1 = workspace.LandingDock.Attachment
	    bodyPosition.Parent = workspace.Boat.BoatSeat
      end
    end	
  end)
end

Local teleporting: To make NPCs teleport locally, the developer would create a pathfinding link between two teleport points, set the label to say “Teleport” and set the cost of Teleport to a low value so that pathfinding favors that path. For example:
3

local link = Instance.new("PathfindingLink", model)
link.Attachment0 = … -- starting point of the link
link.Attachment1 = … -- end point of the link
link.IsBidirectional = false
link.Label = "Boat"

local path = PathfindingService:CreatePath{
      Costs = {
        Teleport = 0.1,
        Plastic = 10,
        Grass = 20
    }
}
path:ComputeAsync(from, to)

if path.Status == Enum.PathStatus.Success then
  -- Get path waypoints
  local waypoints = path:GetWaypoints()
  -- Loop through waypoints
  for _, waypoint in pairs(waypoints) do
      if waypoint.Label == "Teleport" then
           --- Teleport the NPC
      elseif waypoint.Label == "Jump" then
      --- Jump to the next point
    else
      --- Walk to the next point
    end
  end
end

Vertical ladders: Using pathfinding links, pathfinding can now generate a path to climb a vertical ladder.

local link = Instance.new("PathfindingLink", model)
link.Attachment0 = … -- starting point of the link
link.Attachment1 = … -- end point of the link
link.IsBidirectional = false
link.Label = "Jump"

local path = PathfindingService:CreatePath{
    Costs = {
      Jump = 1,
      Plastic = 10
    }
}

path:ComputeAsync(from, to)

if path.Status == Enum.PathStatus.Success then
  -- Get path waypoints
  local waypoints = path:GetWaypoints()
  -- Loop through waypoints
  for _, waypoint in pairs(waypoints) do
     if waypoint.Label = "Jump" then
     --- Jump to the next point.
     if waypoint.Action == Action.WALK then
     --- Walk to the next point
    end
  end
end

How to enable the Pathfinding Links Beta:

  • Go to File → Beta Features in Studio

  • Check the box to the left of “Pathfinding Links”

  • Restart Studio


Visualization:

Pathfinding links visualization is enabled in studio by default. Pathfinding links are not visible during game-play or run mode in the studio.

An example of pathfinding link visualization is shown below. The text “Boat” is the label given to the link and arrows show the directionality. In this case, the link is bi-directional.

In studio edit mode, Pathfinding visualization can be disabled through the following settings:

Debug visualization:

It is possible to see if the link is actually projected to the navmesh using the debug visualization.

To enable it, open the Studio settings and enable the following settings:

By enabling the “Show Navigation Mesh” setting you can see the link in green color. At the end of the link (near the attachments), a green circle means that the endpoint of the link is projected correctly. If both the endpoints are in the green circle, then the link is correctly projected. If one of the circles is red, then the link is not projected properly. Developers might need to place the attachment closer to the surface.

Example of a properly projected pathfinding link with two green circles shown below:

Example of incorrectly projected pathfinding link with one red circle at the end.


This is a beta feature and with that, we would love any and all feedback you have on it!

Thanks so much!


[Update] May 2, 2022

Updated documentation is available here: Link


[Update] May 16, 2022

Looking to use Pathfinding Links in a published experience? Fill out this form: Link

330 Likes

This topic was automatically opened after 10 minutes.

Incredibly excited to see how flexible this appears to be!
Is there any way we could have a “path reversible” property? Allowing A->B to become A<>B ?

Edit: Aha!

11 Likes

Will this only work in Studio, or will this work on the Roblox client too?

6 Likes

I’m pretty sure that’s what link.Bidirectional does.

Correction, the property is actually link.IsBidirectional, the OP needs to correct that in the code examples.

7 Likes

I am honestly happy with the current additions made to the Pathfinding system. What I don’t like though is how it behaves on Terrain. Some waypoints end up inside the freaking Terrain and you need to Raycast from every waypoint to make them appear on the surface. The issue mainly happens when there is like a small elevation in the terrain or something.

I saw that Raycast is being worked on because a user reported that is ignoring some terrain portions, so I am guessing Pathfinding suffers from the same issue.

9 Likes

I like that Roblox is finally back on the track to improve the Pathfinder! :partying_face:

This is really useful in my game CrimeLogic to let cops walk back to their car dynamically, instead of pursuing all the way on foot.

17 Likes

Time to make a plugin to add links to all trusses in a game :stuck_out_tongue:


This is great! Love the updates PathfindingService has been getting lately! Do you have any plans to extend pathfinding through the air? I’d really like to get my anti-exploiter helicopters up and running. For that matter, what about my anti-exploiter fighter jets?

image

image

8 Likes

I might try recreating that “floating warehouse” blimp Amazon demoed a few years ago. Delivery drones can pick up parcels and navigate to the drop-off point, then return to the mothership for their next package. Here’s a prototype version that hides Easter Eggs at pre-designated coordinates:

AutomatedDroneEasterEggDelivery

12 Likes

Sure to be an interesting change.

5 Likes

How would multiple custom actions work?

Will the action that is least costly only run? Or will actions be prioritised and scheduled to run depending on their weighted costs? I.e. an action with a cost of 1 will run, proceeded by an action with a cost of 5.

Other than that, It’s very refreshing to see these sorts of updates. Can’t wait to see greater pathfinding functionality in the future.

4 Likes

Been waiting to use this for a while, can finally finish my project. Awesome work.

3 Likes

I absolutely love this as it makes it way easier to do things like making NPCs climb ladders, use vehicles, teleport between two areas, do cool parkour jumps easier, etc. It’ll be super useful and I will 100% be using it in one of the games I have been working on recently once it comes out of the beta phase.

On the topic of pathfinding; I’d love them to add a system to be able to change the jump height (or jump power) of calculated paths in the future. This would be useful for NPCs with altered jump heights to be able to traverse areas higher or lower than the default jump height or be able to fall to areas without the ability to jump. Having this along with pathfinding links would make pathfinding nearly limitless for developers.

TL;DR: Super cool update. Would love to see an AgentJumpHeight variable for pathfinding added.

10 Likes

Wow, very interesting, I could definitely take advantage of this when released, but why are you using the second parameter in Instance.new()?

2 Likes

Lol no way, I just made a tutorial five days ago on pathfinding modifiers and said I’d release a new video on pathfinding links once Roblox releases it. That was quick!

Thank you for this, I’m sure it’ll be very helpful!

4 Likes

Could we theoretically use this for vehicle AI? It could make my Kart Racer much more engaging.

4 Likes

For closed tracks, it will turn out much better to have node-based steering. In case the map is unknown, you can also use raycasting (and use the sides of the track to steer away).

3 Likes

These npc’s are more realistic than me. Honestly it’s crazy how this works, this is one of the better updates roblox has made in the past few months.

3 Likes

Can we have the place files used for these showcases? Would be very helpful to inspect them myself in detail for better understanding.

Anyways good job!

8 Likes

I’ve waited so long for this. Ladders, jumps and teleports always seemed like a huge issue to create at first and I was figuring out how I could work around it with all the pathfinding limitations.

This is a huge help, thank you.

3 Likes