From 053d4946f499bc25e5963eb76c5f08b20ea9ac75 Mon Sep 17 00:00:00 2001 From: Gabe Hollombe Date: Sun, 17 Feb 2013 20:50:00 +1100 Subject: [PATCH] emit a new changed event if the rotation or position changes between calls to tick --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index b7539a5..09a445c 100644 --- a/index.js +++ b/index.js @@ -118,6 +118,16 @@ PlayerPhysics.prototype.tick = function (delta, cb) { if (!this.freedom['y+']) this.velocity.y = Math.min(0, this.velocity.y) if (!this.freedom['z-']) this.velocity.z = Math.max(0, this.velocity.z) if (!this.freedom['z+']) this.velocity.z = Math.min(0, this.velocity.z) + + if (this.yawObject.position_old && + this.yawObject.rotation_old && + (this.yawObject.position.distanceTo(this.yawObject.position_old) > 0.001 || + this.yawObject.rotation.distanceTo(this.yawObject.rotation_old) > 0.001) + ) { + this.emit('changed') + } + this.yawObject.position_old = this.yawObject.position.clone() + this.yawObject.rotation_old = this.yawObject.rotation.clone() if (cb) cb(this) }