Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Pathfinder/3.5E movement formula

Hello, I am writing a script that calculates the distance between two sets of coordinates based on the page settings (scale, diagonal and type). I have found these math formulas for the following systems/diagonals :  - Chebyshev (D&D 4E) Math.max(Math.abs(currentX - lastX), Math.abs(currentY - lastY)) - Manhattan Math.abs(currentX - lastX) + Math.abs(currentY - lastY) - Euclidean Math.sqrt(Math.pow((currentX - lastX), 2) + Math.pow((currentY - lastY), 2)) But I can't find the math formula for the Pathfinder/3.5E system. Maybe someone from the dev team can help me on this ? Thanks !
Add the larger of the x or y offset to half of the smaller, rounded down (i.e. max(x, y) + floor(min(x, y) / 2)).
Hello Manveti, Thank you for your reply. But is doesn't work with the pathfinder system. Your formula translated in javascript :  Math.max(Math.abs(currentX - lastX), Math.abs(currentY - lastY)) + Math.floor(Math.min((currentX - lastX), (currentY - lastY)) / 2) Here is an example of what the distances should be if a token move from C3 to any other square :  With your formula :  - C3 to D3 = 1 (ok) - C3 to D4 = 1.5 (not ok) - C3 to E3 = 2 (ok) - C3 to E4 = 2.5 (no ok) - C3 to E5 = 3 (ok) As you can see the first diagonal is special with this system. The first diagonal (to the nearest square) is always 1.
I should mention that I don't want to round the distances because I want these distances to be calculate without the grid. So the player can move his token half a unit.
1473190223

Edited 1473192135
chris b.
Pro
Sheet Author
API Scripter
If you are trying to break down the map to half units (half of 5'), then blow up your maps and have every 2x2 grid = 5'x5', that is probably the easiest. then you can use the equation in "units" which are really 2.5', just double the units you use for spells etc. 
1473191715
The Aaron
Pro
API Scripter
This seems to give me what you expected: var start={x:0,y:0},     end={x:1,y:2}, pDist=function(p1,p2){    return Math.max(Math.abs(p1.x-p2.x),Math.abs(p1.y-p2.y))+Math.floor(Math.min(Math.abs(p1.x-p2.x),Math.abs(p1.y-p2.y))/2); }; pDist(start,end); I'm guessing it's the missing Math.abs() calls from the Math.min() side of things causing you problems?
1473199716

Edited 1473199888
Hello, Thanks for the reply. But unfortunately, it still doesn't work, even with your fix Aaron.  I have the same result :  - C3 to D3 = 1 (ok) - C3 to D4 = 1.5 (not ok. Expected : 1) - C3 to E3 = 2 (ok) - C3 to E4 = 2.5 (not ok. Expected : 2) - C3 to E5 = 3 (ok) Also, I don't want to round the final result because I want this to be working without the grid/snap system. So a token can move 0.2m or 1m or 1.3m. EDIT : How can I get a member of the dev team to read this thread ? Obviously they got it working with the "rule tool" :)
1473200476
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Are you trying to get this to work on a gridless map, so that they could move anywhere from 0.0000000001 feet to a full 5 feet? If that's the case, I'd think you might want to look at just tossing out the pathfinder/D&D/misc system's artificial movement scale(and included extra diagonal cost). Where in the diagonal movement would you start to apply the extra movement cost that pathfinder requires for moving every other diagonal square?
@Scott C. : yes, that's what I was thinking. The Pahfinder System use an artificial system. I'm not sure I can find a math formula without the grid (a minimum movement unit)
1473203609
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
you could probably get it down to single foot increments and do some sort of floor(distance/5) or something, but I don't think you're going to be able to do any finer granulation than that (or I suppose 1/2 a foot and then you'd divide by 10 (maybe)).
The diagonal rules are approximations to support gameplay on a grid. If you are not going to use a grid, it's not clear to me why you want to try to use this when you could use the Euclidian setting and get the real distance, as you seem to want when talking about moving 1.3 m. Can you elaborate more what you need that Euclidian doesn't do?
1473209355

Edited 1473209395
chris b.
Pro
Sheet Author
API Scripter
Yes if you are getting rid of the pathfinder grid, then I agree use euclidian. Pathfinder rules are an approximation to fit reality to a grid. But the real world would be euclidian. You might have some argument over whether someone is inside or outside of an area of effect though.
1473211427
The Aaron
Pro
API Scripter
This is a translation of the code that is used for measuring distances in Roll20.  I've restructured it a bit and set it up to work with the API (I didn't bother with the hex portion of the code): var getDistanceInScale = function(startPoint, endPoint, page) { 'use strict'; var measuredLength, lengthInGridUnits = 0, diagonalType = page.get("diagonaltype"), scaleNumber = parseFloat(page.get("scale_number")), distance, lengthX = endPoint.x - startPoint.x, lengthY = endPoint.y - startPoint.y; switch(diagonalType){ case 'foure': lengthX = Math.abs(lengthX); lengthY = Math.abs(lengthY); distance = Math.max(lengthX, lengthY); break; case "threefive": lengthX = Math.abs(lengthX); lengthY = Math.abs(lengthY); var gridSize = Math.round( parseFloat( page.get("snapping_increment") || 1 ) * 70 ); lengthInGridUnits = Math.floor(Math.min(lengthX, lengthY) / gridSize); distance = Math.floor(lengthInGridUnits / 2) * gridSize + Math.max(lengthX, lengthY); break; default: distance = "manhattan" == diagonalType ? Math.abs(lengthX) + Math.abs(lengthY) : Math.sqrt(lengthX * lengthX + lengthY * lengthY); break; } measuredLength = distance / 70; return Math.round(measuredLength * scaleNumber * 10) / 10; }; The return is the distance in Units between the two points using the settings of the provided page.
1473287414

Edited 1473287610
Andrew C
Marketplace Creator
For sanity, if you want to "eliminate the 3.5E grid" then I recommend you create 1ft Hex as your base and then round up. Medium Tokens take a hex plus two hexes around. Large tokens have a hex plus 4 hex around. Reach weapons hit over 4 hex but not under 4 hex, etc
I will not try to calculate the distance between to sets of coordinates without the grid for Pathfinder/3.5E. This is indeed pointless. Thank you all for your time and replies :)