Commits

Eric Fredricksen  committed de30375

Keep track of distance travelled by entities for later head bob usage

  • Participants
  • Parent commits 9559297

Comments (0)

Files changed (1)

 function ballistics(e, elapsed) {
   // Apply the laws of pseudo-physics
 
+  var origin = {x: e.x, y: e.y, z: e.z};
+
   e.swimming = e.falling && block(e).type.liquid;
 
   if (e.ddx || e.ddz) {
     e.dy = 0;
   }
 
+  e.travelled += distance(e, origin);
+
   if (blocke.type.onstep)
     blocke.type.onstep.call(blocke, e);
 
   init('pitch', 0);
   init('dyaw', 0);
   init('dpitch', 0);
+  init('travelled', 0);
   //init('falling', false);
   init('birthday', GAME.clock);
   init('id', function () { return GAME.nextEntityID++} );
 
 Entity.prototype.data = function () {
   var result = {};
-  var keeps = 'x y z dx dy dz yaw pitch dyaw dpitch birthday id'.split(' ');
+  var keeps = 'x y z dx dy dz yaw pitch dyaw dpitch travelled birthday id'.split(' ');
   for (var i = 0; i < keeps.length; ++i) {
     var k = keeps[i];
     result[k] = this[k];