token.getLineOfSightTo()
Ask whether this token can see another one, given the walls on the map.
Part of the Action API · Function reference
Available on token, target, and every entry of targets.
Signature
token.getLineOfSightTo(otherToken: string | Token): boolean
Synchronous.
Parameters
| Parameter | Type | Description |
|---|---|---|
otherToken |
string | Token |
The other token, as an object or as a token id string. |
Returns
boolean — true when the view is clear, false when a vision-blocking shape
is in the way.
Also false when the other token cannot be found, so an unresolvable id reads
as "cannot see" rather than throwing.
How it decides
A ray is cast from this token's position to the other token's, and tested
against the map's vision-blocking shapes — the same walls that drive
fog and lighting, including any created by
draw({ shape: 'wall' }).
What it does not consider:
- distance, darkness, or light level
- token size — the test is centre to centre, so a corner peeking past a wall does not count
- elevation or wall height
- vision types, senses, invisibility, or cover rules
It answers one question: is there a wall between these two points.
Examples
Require a clear shot
if (!target) return 'No target.';
if (!token.getLineOfSightTo(target)) {
return `${token.name} cannot see ${target.name}.`;
}
target.applyDamage(roll('1d8+3'), 'piercing');
Only affect what you can see
const visible = targets.filter((t) => token.getLineOfSightTo(t));
const damage = roll('6d6', { label: 'Blast' });
for (const t of visible) t.applyDamage(damage, 'fire');
if (visible.length < targets.length) {
sendMessage('<i>Some targets were behind cover.</i>');
}
Range and sight together
const canHit = targets.filter(
(t) => token.getDistanceTo(t) <= 12 && token.getLineOfSightTo(t),
);
Cover as a penalty instead of a block
const seen = token.getLineOfSightTo(target);
const attack = roll(seen ? '1d20+5' : '1d20+3', { label: seen ? 'Attack' : 'Attack (obscured)' });
Notes and gotchas
- Only walls block. Distance, darkness, and invisibility are yours to handle.
- Centre to centre. Large tokens are treated as points, so results near a wall's edge can disagree with what the map looks like.
falseon failure. An unresolvable token id is indistinguishable from a blocked view.- Symmetric.
a.getLineOfSightTo(b)andb.getLineOfSightTo(a)agree; there is no one-way glass.
See also
getDistanceTo()draw()— creating walls from an action- Drawings, fog, and lighting