diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 1a15165..3700ea5 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -44,7 +44,7 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( deltaTime, parentEntity ) { - var forward = false; + var forward = true; var backward = false; var left = false; var right = false; diff --git a/src/game-lib-component-rotator.js b/src/game-lib-component-rotator.js new file mode 100644 index 0000000..65e1e7a --- /dev/null +++ b/src/game-lib-component-rotator.js @@ -0,0 +1,72 @@ +/** + * + * @param id + * @param name + * @param axis {GameLib.D3.Vector3} + * @param getRotationFunc {Number} + * @constructor + */ +GameLib.D3.ComponentRotator = function ComponentRotator( + id, + name, + axis, + getRotationFunc +) { + this.id = id || GameLib.D3.Tools.RandomId(); + + if (typeof name == 'undefined') { + name = this.constructor.name; + } + this.name = name; + this.parentEntity = null; + + this.axis = axis || new GameLib.D3.Vector3(); + this.getRotationFunc = getRotationFunc || function(){} ; + + GameLib.D3.Utils.Extend(GameLib.D3.ComponentRotator, GameLib.D3.ComponentInterface); +}; + +//#ifdef RUNTIME__ + +///////////////////////// Methods to override ////////////////////////// +GameLib.D3.ComponentRotator.prototype.onLateUpdate = function( + deltaTime, + parentEntity +) { + if(parentEntity) { + + var quat = new THREE.Quaternion( + parentEntity.quaternion.x, + parentEntity.quaternion.y, + parentEntity.quaternion.z, + parentEntity.quaternion.w + ).multiply( + new THREE.Quaternion().setFromAxisAngle( + new THREE.Vector3( + this.axis.x, + this.axis.y, + this.axis.z + ), + this.getRotationFunc() + ) + ); + + + /* var quat = new THREE.Quaternion().setFromAxisAngle( + new THREE.Vector3( + this.axis.x, + this.axis.y, + this.axis.z + ), + this.getRotationFunc() + );*/ + + parentEntity.quaternion.x = quat.x; + parentEntity.quaternion.y = quat.y; + parentEntity.quaternion.z = quat.z; + parentEntity.quaternion.w = quat.w; + + parentEntity.mesh.updateMatrix(); + } +}; +//#endif \ No newline at end of file