From 8ddba38561e88e695ff93a276fea437207a08fa6 Mon Sep 17 00:00:00 2001 From: polygonboutique Date: Tue, 8 Nov 2016 12:04:42 +0100 Subject: [PATCH] added more settings for follow & look at components --- src/game-lib-component-follow.js | 31 ++++++++++++++++++++++++++----- src/game-lib-component-look-at.js | 6 +++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/game-lib-component-follow.js b/src/game-lib-component-follow.js index 162f9dc..d1f8a87 100644 --- a/src/game-lib-component-follow.js +++ b/src/game-lib-component-follow.js @@ -2,7 +2,8 @@ GameLib.D3.ComponentFollow = function( componentId, targetEntity, targetOffset, - minDistance + minDistance, + moveSpeed ) { this.componentId = componentId || GameLib.D3.Tools.RandomId(); this.parentEntity = null; @@ -12,7 +13,7 @@ GameLib.D3.ComponentFollow = function( // this.targetEntity = targetEntity; - this.moveSpeed = 12.5; + this.moveSpeed = moveSpeed || 12.5; if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) { @@ -25,6 +26,8 @@ GameLib.D3.ComponentFollow = function( ComponentFollow_Target_Vec3 = new THREE.Vector3(); ComponentFollow_TargetToParent_Vec3 = new THREE.Vector3(); +ComponentFollow_rotatedTargetOffset_Vec3 = new THREE.Vector3(); +ComponentFollow_tempQuaternion = new THREE.Quaternion(); ///////////////////////// Methods to override ////////////////////////// GameLib.D3.ComponentFollow.prototype.onUpdate = function( @@ -34,10 +37,28 @@ GameLib.D3.ComponentFollow.prototype.onUpdate = function( if(this.targetEntity) { + ComponentFollow_tempQuaternion.set( + this.targetEntity.quaternion.x, + this.targetEntity.quaternion.y, + this.targetEntity.quaternion.z, + this.targetEntity.quaternion.w + ); + + ComponentFollow_rotatedTargetOffset_Vec3.set( + this.targetOffset.x, + this.targetOffset.y, + this.targetOffset.z + ); + + ComponentFollow_rotatedTargetOffset_Vec3 = + ComponentFollow_rotatedTargetOffset_Vec3.applyQuaternion( + ComponentFollow_tempQuaternion + ); + ComponentFollow_Target_Vec3.set( - this.targetEntity.position.x + this.targetOffset.x, - this.targetEntity.position.y + this.targetOffset.y, - this.targetEntity.position.z + this.targetOffset.z + this.targetEntity.position.x + ComponentFollow_rotatedTargetOffset_Vec3.x, + this.targetEntity.position.y + ComponentFollow_rotatedTargetOffset_Vec3.y, + this.targetEntity.position.z + ComponentFollow_rotatedTargetOffset_Vec3.z ); ComponentFollow_TargetToParent_Vec3.set( diff --git a/src/game-lib-component-look-at.js b/src/game-lib-component-look-at.js index 811ab40..a2944e7 100644 --- a/src/game-lib-component-look-at.js +++ b/src/game-lib-component-look-at.js @@ -1,7 +1,8 @@ GameLib.D3.ComponentLookAt = function( componentId, targetEntity, - targetOffset + targetOffset, + rotationSpeed ) { this.componentId = componentId || GameLib.D3.Tools.RandomId(); this.parentEntity = null; @@ -17,9 +18,8 @@ GameLib.D3.ComponentLookAt = function( } this.targetOffset = targetOffset; - this.lastTargetPosition = new GameLib.D3.Vector3(0, 0, 0); this.lastTargetQuaternion = new GameLib.D3.Vector4(0, 0, 0, 1); - this.rotationSpeed = 22.0; + this.rotationSpeed = rotationSpeed || 22.0; };