Based on substack's voxel-player module (https://github.com/substack/voxel-player).
Create a dummy player object which can be manipulated by API methods.
var createGame = require('voxel-hello-world');
var game = createGame();
var createDummy = require('./')(game);
var dummy1 = createDummy('skin1.png');
dummy1.yaw.position.set(0,2,-2);
var createPlayer = require('voxel-player')(game);
var player = createPlayer('skin1.png');
player.position.set(0,2,0);
player.possess();
dummy1.faceTowards(player);
window.addEventListener('keydown', function (ev) {
if (ev.keyCode === 'R'.charCodeAt(0)) {
player.toggle();
}
if (ev.keyCode === 'F'.charCodeAt(0)) {
dummy1.faceTowards(player);
}
if (ev.keyCode === 'J'.charCodeAt(0)) {
dummy1.jump(0.3);
}
});
var voxelDummy = require('voxel-dummy-player')
Return a function createDummy
from a
voxel-engine game
instance.
Return a new dummy from a image file src string img
.
Set the dummy position.
Subject the dummy to a force of gravity or some such. The default value is
a THREE.Vector3 with { x: 0, y: -0.00009, z: 0 }
.
Move a relative amount with (x, y, z)
or a THREE.Vector3 vec
.
Move to an absolute position with (x, y, z)
or a THREE.Vector3 pos
.
Rotate body a relative amount with (x, y, z)
or a THREE.Vector3 vec
.
Rotate body to an absolute position with (x, y, z)
or a THREE.Vector3 pos
.
Rotate dummy to face towards object position.
Rotate head a relative amount with (x, y, z)
or a THREE.Vector3 vec
.
Rotate head to an absolute position with (x, y, z)
or a THREE.Vector3 pos
.
Rotate dummy head to look at object position.
Make dummy jump by height of y.
MIT
With npm do:
npm install voxel-dummy-player
If created after player it auto-possesses the dummy. Not sure why, but feel free to help out :)