added more settings for follow & look at components

beta.r3js.org
polygonboutique 2016-11-08 12:04:42 +01:00
parent de5961456f
commit 8ddba38561
2 changed files with 29 additions and 8 deletions

View File

@ -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(

View File

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