voxel-trajectory

Calculate a trajectory in voxel.js

voxel-trajectory

Calculate trajectories in voxel.js.

View the voxel-throw example

example

Create a trajectory to throw an item based on the direction the camera is facing:

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:

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}
  })
};

api

trajectory([velocity:number, rotation:{x,y}, origin:{x,y,z}])

install

With npm do:

npm install voxel-trajectory

Use browserify to require('voxel-trajectory').

  • 0.1.0 - initial release

Copyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.