pf2e
pf2e copied to clipboard
RulerPF2e - Add Hexagonal Segment Highlighting
This adds "fat ruler" highlighting to the ruler for hexagonal grids. It does this in a universal way for both square grids and hexagonal grids.
Using grid offsets on a hexagonal grid leads to some wonky behaviour if you are only using them to get neighboring hexes. For example, the hex to the top-left might be to the top-left in offset notation but depending on the grid layout and the current row/hex it might be to the top or the left in offset notation.
The proper way would probably use offset coordinates for square grids, and cube coordinates for hexagonal grids. However, a third option is to just use x/y offsets from the origin to represent a token's shape which works on both types of grids.
This leads to another wonky behaviour with hexagonal grids. On a square grid if a point is on the vertex touching four different squares then Foundry is always going to pick the same grid when you get the offset coordinates of that point. However, on a hexagonal grid this is not always the case when the point is on the vertex touching three different hexes thanks to floating point math. So depending on the layout of the hexagonal grid and if you are on an odd or even row/column it will pick different hexes when you get the offset/cube coordinates of that point. This leads to some wonky behaviour when you ask Foundry to get a direct path between the two points, it can pick the hex to the top-left of the start point and the hex to the top-right of the end point which means the token appears to be going to far.
To resolve that problem we instead standardize which grid we are going to use for the direct path, if the token's center is in-between squares/hexes it always using the grid that is to the top-left of both the start and end point when getting the direct path for a segment. Then we can reverse this offset to determine where a token's center is at any point along the direct path, then use the offsets' from the token's center we get from the token's shape to get all the squares/hexes we need to highlight.
Below is a sample from moving a large creature on a hexagonal map.
Foundry_Virtual_Tabletop_VmE6gGwnKK.webm
Below is a sample from moving a large creature on a square map, showing that it still behaves the same.