Skip to content

See units behind trees ​

Trees and scenery between the camera and a unit can be faded, or have a hole cut around the unit (GameView.world.seeThrough). It's off until the game or map turns it on; every starter turns it on.

ts
// in src/game.ts
import { type GameView } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { rules } from './rules'

export const view: GameView = {
	units: {
		looks: {}
	},
	world: {
		// as it comes: the player's own units, what is in the way faded to 30% over a quarter of a second, trees and scenery
		seeThrough: {}
	}
}

// or every knob
export const tuned: GameView = {
	units: {
		looks: {}
	},
	world: {
		seeThrough: {
			// whose units: 'own', 'selected', 'allies', 'all', or code
			who: (unit) => unit.isUnit && !unit.hidden,
			// 'fade' all of it, 'cutout' a hole round each unit, 'none' to show it your own way (`client.seeThrough.occluders`)
			style: 'cutout',
			// how much of it is still drawn, how fast, how big a hole
			opacity: 0.2,
			fade: 0.4,
			radius: 2,
			// what is seen through
			trees: true,
			doodads: true,
			buildings: true
		}
	}
}

export const game = createGame(rules).view(view)

Done: seeThrough: {} fades whatever hides your own units to 30%. The tuned view cuts a 2-cell hole instead, for every visible unit, through trees, scenery and buildings.

Control it in code ​

ts
// your own units to see through to, in place of `who`: a cinematic's hero, a point of the map
client.seeThrough.targets = (units) => [...units, { x: 40, y: 0, z: 30, height: 2, radius: 1 }]
// thing by thing: never the town hall
client.seeThrough.decide = (thing) => (thing.kind === 'building' && thing.id === hallId ? false : undefined)
// a tree held seen through until let go
const letGo = client.seeThrough.hold('tree', treeId)
// what is in the way now, each with how faded it is
for (const thing of client.seeThrough.occluders) console.log(thing.kind, thing.id, thing.fade)
// a mesh of your own takes it by where its copies stand, or by its vertices
mesh.metadata = { ...mesh.metadata, seeThrough: 'vertex' }

In the editor ​

  1. Open the Look panel's See through fold.
  2. Set the map's own: on or off, whose units, fade or cutout, opacity, speed, hole size, which kinds.
  3. Check it in Play here. The editor's own view always draws everything whole.

Reference ​

FieldWhat it does
who'own' (default), 'selected', 'allies', 'all', or a function.
style'fade', 'cutout', or 'none' to draw it yourself.
opacityHow much is still drawn (default 0.3).
fadeSeconds to ease in and out.
radiusThe hole's size, for cutout.
trees, doodads, buildingsWhat is seen through.

The map's setting (MapEnvironment.seeThrough) goes over the game's. It costs about 0.1 ms a frame for 5,600 trees; shadows stay.