Make bushes of my own
Draw a layer of cells as your own models with foliage({ models }). Each bush is picked by weight and gets its own turn, size and lean. Bushes sway in the wind and shake as units walk into them.
// in src/game.ts
import { createGame, defineCellLayer, foliagePack, type Rules } from '@v12-engine/engine'
import { CELL_LAYERS_FILE, foliage, type GameView, layFiles } from '@v12-engine/client'
import { rules } from './rules'
// a layer of cells the editor paints; its style hides whoever stands in it
export const bushRules: Rules = {
...rules,
cellLayers: [defineCellLayer({ id: 'bush', name: 'Bushes', color: [0.2, 0.7, 0.2], values: [{ value: 1, name: 'Bushes', foliage: { conceals: true, flammable: 0.4 } }] })],
packs: [...(rules.packs ?? []), foliagePack({ layer: 'bush' })]
}
// what the editor wrote (cellLayers.json) is laid over the code: `[CELL_LAYERS_FILE, file]` with `import file from './cellLayers.json'`
export const view: GameView = layFiles(
{
units: { looks: {} },
ground: {
cellLayers: {
bush: foliage({
models: [{ src: 'forest/bush_common_flowers.glb' }, { src: 'forest/bush_common.glb', weight: 0.2 }], // a few with red leaves, as in autumn
density: 0.8, // models per cell: a fraction is a chance of one
height: 1.2, // scaled to 1.2 tall; left out, each keeps the size it was made at
sizes: { each: [0.8, 1.3] },
rotation: { lean: 8 },
walked: { bend: 1.2, radius: 1.8, settle: 1.4, entry: 2.5 },
sound: 'rustle',
leaves: 'leaves', // the ready-made effect, played where a unit steps in
shadow: 'near'
})
}
}
},
[[CELL_LAYERS_FILE, {}]]
)
export const game = createGame(bushRules).view(view)Done: paint Bushes in the editor's Terrain panel. The two models scatter over the cells. They rustle and drop leaves as units step in, and hide whoever stands inside.
Bushes and grass on one layer
One style can draw models while the rest of the layer is grass:
import { foliage } from '@v12-engine/client'
export const field = foliage({
density: 4, // value 1: grass
styles: {
2: { draw: 'models', models: [{ src: 'forest/bush_common_flowers.glb' }], density: 0.7, colors: { tint: [0.9, 1, 0.8], vary: 0.1 } }
},
levels: { mid: 60, far: 100, cull: 160 } // bushes: the model, then its .lod1 and .lod2 files, none past 160 cells
})A thicket nothing walks through
import { defineCellLayer } from '@v12-engine/engine'
export const hedges = defineCellLayer({
id: 'bush',
name: 'Bushes',
values: [
{ value: 1, name: 'Bushes', foliage: { conceals: true } },
{ value: 2, name: 'Thicket', foliage: { conceals: true, speed: 0.6 } }, // slows units passing through
{ value: 3, name: 'Hedge', foliage: { walkable: false } } // paths go round it
]
})Painting or clearing a style with speed or walkable: false while the game runs recalculates the navigation where it changed. That takes a few milliseconds per call on a big map, so avoid doing it every tick.
Give away hidden units' movement
Use foliagePack({ layer: 'bush', conceal: { rustle: true } }). Teams that can't see a hidden unit are told where it moves, but never who it is, about every 0.3 s (rustleEvery), and their bushes shake there. If a game only wants hiding, with no styles, fire or trampling, it can use concealmentPack({ layer: 'bush' }) instead.
Shake or change bushes in code
import type { World } from '@v12-engine/engine'
import type { GameClient } from '@v12-engine/client'
declare const client: GameClient
declare const world: World
client.foliage('bush')?.disturb({ x: 20, z: 20 }, 2) // an explosion, a deer
client.foliage('bush')?.setStyle(2, { colors: { tint: [0.8, 0.9, 0.6] } }) // on this screen
world.setEnvironment({ bushes: { bush: { wind: { sway: 3 } } } }) // from the rules: every player sees itChanging a bush style while the game runs lays out again only the chunks that hold it.
Cut and burnt bushes
Bushes follow the layer's state just as grass does. When cut, they stand as stumps at ruined.stubble of their height. When burning, they char. When burnt, they are black and have lost most of their leaves. They shake, but they are never laid flat.
In the editor
- In the Terrain panel, paint with the layer's style.
- Open Grass and bushes. In Drawn as, pick Models.
- Add a model… from your files, or Upload… a GLB, and set each one's weight.
- Set the rest group by group: Size, Rotation, Colour, Placing, Wind, Walked on, Distance, Ruined, Sound and leaves.
- Under Set for, pick This map or Every map (the game's) (written to
cellLayers.json).
See Grass and bushes in the editor.
Reference
Bushes read these parts of a look: models, density (default 0.7), height, sizes, rotation (lean default 6), placing (jitter default 0.7; nothing kept off unless keepOff says so), seed, noise, colors (tint, dry, vary, hue, patches), levels, the layer's wind, walked (bend, radius, settle, entry, who), ruined (stubble, burnt), shadow, sound, volume, leaves, seeThrough.
They ignore shape, light, scatter, colors.foot, tip, stops, saturation, ground, a style's own wind, and walked.flatten. Far away they draw their lightest model, and past that nothing: bushes have no impostor pictures. Without levels, a model's levels are the game's detail levels for it (GameView.world.detail).
Bushes are laid out in chunks of 32 cells and drawn as one mesh per model and level. Every field is listed in Grass and bushes.