AI Pathfinding

From RPTools Wiki
Jump to navigation Jump to search


MapTool has a built in AI pathfinding feature. When activated via the ‘AI’ toggle button on the toolbar, tokens will find the shortest path to its destination as you drag them on the token or hidden layers. The movement takes into account VBL and terrain modifiers configured on intervening tokens. This means your tokens will not move through walls, and will find an efficient path past obstacles and around or through difficult terrain. AI Pathfinding correctly accounts for a game's diagonal movement settings as well.

The AI setting can be toggled by clicking the 'AI' button on the toolbar so that it shows green text. When the text is gray, AI is disabled. This setting is per client only, and cannot be enforced by a game host.

Using Terrain Modifiers

Editing a stamp's terrain modifier

A stamp's Terrain Modifier multiplies the map's 'Distance per Cell' cost of moving into that token’s cell and is taken into account when AI Pathfinding is used. Some examples are: On a default map with 'Distance per Cell' set to 5.0, setting the multiplier to 2 will cost 10 feet of movement instead of 5, acting like difficult terrain.

Setting the multiplier to a sufficiently high number, like 99999, will effectively block the movement and make the token go around the obstacle. This is useful for things like an arrow slit, window, lava, etc. Any token can have this modifier which means you can set NPC tokens so PCs must go around them or stamp tokens on the object layer like oil or water. You can also place tokens on the hidden layer to denote difficult terrain.

To set the terrain modifier of a token, open the Token Editor by double clicking the token or accessing it via the right-click menu. Navigate to the Config tab and set the Terrain Modifier. You can also set the token opacity from here, which may be useful for creating translucent terrain markers.

Once created, tokens with terrain modifiers can be placed on any layer (including the hidden layer) and still affect other tokens' movement.

Example map using AI

Left: Setting up a map with vision blocking and terrain modifiers for use with AI pathfinding. Right: A token being moved across the sample map with AI enabled.

The sample map pictured was created by creating a large block of VBL (the blue area) and removing squares of it by holding down the shift key while placing rectangles of VBL. There is also VBL on the stamped steps as well to make the PCs navigate them as they should.

The Map Units are set to '1' on this map to make it easy to see the multiplier at work. The staircase stamp has a terrain value of 2 as do the other steps in the horizontal corridor (note the image under 'Using Terrain Modifiers'). If the map units were set to '5', a terrain modifier of 2 would make the steps cost 10 units to enter.

With the movement AI enabled, the PC can be dragged anywhere but should go around VBL and suffer appropriate movement penalties when passing over tokens with a Movement Modifier.

Overriding AI

But I want to jump in the lava pit!

If you absolutely, positively, despite all warnings to the contrary want to enter difficult terrain, you can use the spacebar to set a waypoint to force the path. You can also use this to get into a more advantageous attack position even over difficult terrain.

Limitations

There are a few limitations to the movement AI:

  • Pathfinding only works on maps with a grid type set.
  • The token being moved cannot be free-size and must be snap to grid.
  • Tokens with Terrain Modifiers must be set to a named size (e.g. Medium or Large) and cannot be set to Free Size or they will not work.
  • No macros exist to access AI features, nor server options to force players to use this mode of moving tokens.
  • There are no fractional (e.g. 2.5x) or arbitrary (e.g. +5 units) terrain modifiers at this time, only an integer multiplier. As of 1.5.11, fractional modifiers can be used for both Multiply and Add types.
  • If your rule system states that the square on either side must be open in order to move diagonally then you will need to use the spacebar to set a waypoint to navigate corners.
  • If a token is dragged to an area to which no path can be found then no path at all will be shown. You can still move your token to the new location, but if the token is dropped by a player into such a square it might become invisible to them.
  • With MapTool allowing unbounded/nearly infinite map space, we had to include a timeout to prevent an infinite search. When moving a token on a very complex path or where no path is available, MapTool may seemingly hang several seconds as it searches for a path before placing a token.