Calculate a trajectory in voxel.js
npm install voxel-trajectory> Calculate trajectories in voxel.js.
Create a trajectory to throw an item based on the direction the camera is
facing:
`` js
var trajectory = require('voxel-trajectory');
// x,y of voxel.js camera
var camera = game.cameraRotation();
// rotate the axis -90 degs to throw forward
camera.x -= Math.PI / 2;
// create an item with a velocity of 2 towards trajectory
var item = {
velocity: trajectory(2, camera),
mesh: / ... /,
size: game.cubeSize,
resting: false
};
game.addItem(item);
`
The trajectory can be from anywhere, such as a meteor:
`js`
var meteor = {
velocity: trajectory({
// pretty fast
velocity: 5,
// 45 degrees
rotation: {x: Math.PI / 180 45, y: Math.PI / 180 45},
// from the sky
origin: {x: 1000, y: 5000, z: 1000}
})
};
trajectory([velocity:number, rotation:{x,y}, origin:{x,y,z}])
With npm do:
``
npm install voxel-trajectory
Use browserify to require('voxel-trajectory')`.