added more settings for follow & look at components
parent
de5961456f
commit
8ddba38561
|
@ -2,7 +2,8 @@ GameLib.D3.ComponentFollow = function(
|
||||||
componentId,
|
componentId,
|
||||||
targetEntity,
|
targetEntity,
|
||||||
targetOffset,
|
targetOffset,
|
||||||
minDistance
|
minDistance,
|
||||||
|
moveSpeed
|
||||||
) {
|
) {
|
||||||
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
@ -12,7 +13,7 @@ GameLib.D3.ComponentFollow = function(
|
||||||
|
|
||||||
//
|
//
|
||||||
this.targetEntity = targetEntity;
|
this.targetEntity = targetEntity;
|
||||||
this.moveSpeed = 12.5;
|
this.moveSpeed = moveSpeed || 12.5;
|
||||||
|
|
||||||
|
|
||||||
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
if(GameLib.D3.Utils.UndefinedOrNull(targetOffset)) {
|
||||||
|
@ -25,6 +26,8 @@ GameLib.D3.ComponentFollow = function(
|
||||||
|
|
||||||
ComponentFollow_Target_Vec3 = new THREE.Vector3();
|
ComponentFollow_Target_Vec3 = new THREE.Vector3();
|
||||||
ComponentFollow_TargetToParent_Vec3 = new THREE.Vector3();
|
ComponentFollow_TargetToParent_Vec3 = new THREE.Vector3();
|
||||||
|
ComponentFollow_rotatedTargetOffset_Vec3 = new THREE.Vector3();
|
||||||
|
ComponentFollow_tempQuaternion = new THREE.Quaternion();
|
||||||
|
|
||||||
///////////////////////// Methods to override //////////////////////////
|
///////////////////////// Methods to override //////////////////////////
|
||||||
GameLib.D3.ComponentFollow.prototype.onUpdate = function(
|
GameLib.D3.ComponentFollow.prototype.onUpdate = function(
|
||||||
|
@ -34,10 +37,28 @@ GameLib.D3.ComponentFollow.prototype.onUpdate = function(
|
||||||
|
|
||||||
if(this.targetEntity) {
|
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(
|
ComponentFollow_Target_Vec3.set(
|
||||||
this.targetEntity.position.x + this.targetOffset.x,
|
this.targetEntity.position.x + ComponentFollow_rotatedTargetOffset_Vec3.x,
|
||||||
this.targetEntity.position.y + this.targetOffset.y,
|
this.targetEntity.position.y + ComponentFollow_rotatedTargetOffset_Vec3.y,
|
||||||
this.targetEntity.position.z + this.targetOffset.z
|
this.targetEntity.position.z + ComponentFollow_rotatedTargetOffset_Vec3.z
|
||||||
);
|
);
|
||||||
|
|
||||||
ComponentFollow_TargetToParent_Vec3.set(
|
ComponentFollow_TargetToParent_Vec3.set(
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
GameLib.D3.ComponentLookAt = function(
|
GameLib.D3.ComponentLookAt = function(
|
||||||
componentId,
|
componentId,
|
||||||
targetEntity,
|
targetEntity,
|
||||||
targetOffset
|
targetOffset,
|
||||||
|
rotationSpeed
|
||||||
) {
|
) {
|
||||||
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
this.componentId = componentId || GameLib.D3.Tools.RandomId();
|
||||||
this.parentEntity = null;
|
this.parentEntity = null;
|
||||||
|
@ -17,9 +18,8 @@ GameLib.D3.ComponentLookAt = function(
|
||||||
}
|
}
|
||||||
this.targetOffset = targetOffset;
|
this.targetOffset = targetOffset;
|
||||||
|
|
||||||
this.lastTargetPosition = new GameLib.D3.Vector3(0, 0, 0);
|
|
||||||
this.lastTargetQuaternion = new GameLib.D3.Vector4(0, 0, 0, 1);
|
this.lastTargetQuaternion = new GameLib.D3.Vector4(0, 0, 0, 1);
|
||||||
this.rotationSpeed = 22.0;
|
this.rotationSpeed = rotationSpeed || 22.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue