voxel-debris
create and collect voxel debris from exploded voxels
example
var createEngine =var game =;game;var explode = game power : 15 ;explode;game;window;window;var erase = true{ erase = !evctrlKey }game;
methods
var voxelDebris =
var explode = voxelDebris(game, opts)
Create an explosion function from a voxel-engine instance and some options.
If opts.limit(item)
is specified, when it returns true, item
will not be
collected by the player when they pass within the collision radius.
If opts.yield(value)
is specified, its return value will be how many debris
items are created for the voxel data value
. opts.yield
can be a function or
just a number.
opts.expire.start
and opts.expire.end
control how long debris should persist
in the game world in milliseconds. A timeout will be chosen uniformly randomly
between start and end.
When opts.expire
is a number, its value will be used for both start and end.
opts.power
influcences the velocity of the debris. Default value: 1.
explode(pos)
Explode the block at the THREE.Vector3 position pos
if the data at pos
is
non-zero.
events
explode.on('collect', function (item) {})
When a debris item passes within the collision radius, the 'collect'
event
fires with the item object before being removed from the scene.
install
With npm do:
npm install voxel-debris
Then use browserify to require('voxel-debris')
.
license
MIT