calculating range/distance

I am trying to calculate the distance between two tokens to make sure they are in range of one another before applying an action. Though I am not sure the best way to go about this. I have tried the following which works, but it feels wrong. What is the best way to get an actors token?
// t comes from game.users.current.targets as I iterate through the current targets of the user

// needing to go from actor to the sheet to get the token seems weird!
const actorToken = actor.sheet.token;
const distance = canvas.grid.measureDistance({ x: actorToken.x, y: actorToken.y }, { x: t.x, y: t.y });
if (distance < 10) {
target = t.actor;
}
// t comes from game.users.current.targets as I iterate through the current targets of the user

// needing to go from actor to the sheet to get the token seems weird!
const actorToken = actor.sheet.token;
const distance = canvas.grid.measureDistance({ x: actorToken.x, y: actorToken.y }, { x: t.x, y: t.y });
if (distance < 10) {
target = t.actor;
}
3 Replies
Aaron
Aaron•11mo ago
actor.getActiveTokens()
Eclipxs
EclipxsOP•11mo ago
thanks! is this otherwise an ok way to go about calculating range?
Zhell🎄
Zhell🎄•11mo ago
Token placeables have a center getter, while if you use their x and y properties you are only getting their top left coordinates.
Want results from more Discord servers?
Add your server