voxel-creature
create creatures for voxel.js
example
var createGame = ;var voxel = ;var game =;game;var createPlayer = game;var substack = ;substack;windowsubstack = substack;window;var createCreature = game;var creature =;windowcreature = creature;creaturepositiony = 200;creaturepositionx = Math * 300 - 150;creaturepositionz = Math * 300 - 150;creature;creature;creature;;
methods
var voxelCreature =
var createCreature = voxelCreature(game)
Return a function createCreature
for making creatures given a
voxel-engine game
instance.
var creature = createCreature(obj, opts={})
Create a creature with the three.js 3d object (use game.THREE) obj
.
Control the bounding box size with a vector3 opts.dims
and the force
(like gravity) for the object to be subject to with opts.force
.
The default opts.dims
is [10,10,10]
.
The default opts.force
is [0,-0.00009,0]
.
creature.jump(power=1)
Jump upward.
creature.move(x, y, z)
Move the creature [x,y,z]
smoothly by altering its velocity.
creature.lookAt(target)
Turn toward the 3d object target
.
target
should be a 3d vector itself or it should have a target.position
.
creature.notice(target, opts)
Return an interval for detecting the presence of target
.
target
should be a 3d vector itself or it should have a target.position
.
The opts.radius
controls how nearby target
needs to be to trigger a
'notice'
event. Otherwise 'frolic'
events fire.
The default opts.radius
is 500
.
The opts.collisionRadius
controls how nearby target
needs to be to trigger a
'collide'
event.
The default opts.collisionRadius
is 25
.
The opts.interval
controls how often to check the distance to target
.
The default opts.interval
is 1000
.
events
creature.on('notice', function (target) {})
When target
is within the radius configured by creature.notice()
, the
'notice'
event fires.
creature.on('collide', function (target) {})
When target
is within the collision radius configured in creature.notice()
,
the 'collide'
event fires.
creature.on('block', function () {})
When a creature is constrained by a block in front of it, the 'block'
event
fires. A good thing to try when a creature is blocked is to jump.
attributes
creature.position
control the creature item position
creature.rotation
control the creature item rotation
install
With npm do:
npm install voxel-creature
license
MIT