server comm
parent
7001449c56
commit
252067c4c8
|
@ -69,14 +69,23 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
|
||||
if(this.splineCurve3 && this.trackThreeMeshArray) {
|
||||
|
||||
this.grain = deltaTime / 100;
|
||||
// current speed
|
||||
|
||||
var currentPosition = this.splineCurve3.getPoint(this.currentPathValue);
|
||||
this.maxSpeed = 0.03;
|
||||
this.accel = 0.1;
|
||||
|
||||
this.currentSpeed += this.accel * deltaTime * this.direction;
|
||||
if(this.currentSpeed > this.maxSpeed) {
|
||||
this.currentSpeed = this.maxSpeed;
|
||||
}
|
||||
this.grain = (this.currentSpeed / 100.0);
|
||||
|
||||
//this.grain = (deltaTime / 100.0);
|
||||
|
||||
var currentPosition = this.splineCurve3.getPointAt(this.currentPathValue);
|
||||
|
||||
this.currentPathValue += this.grain;
|
||||
|
||||
var futurePosition = this.splineCurve3.getPoint(this.currentPathValue);
|
||||
|
||||
if (this.currentPathValue >= 1) {
|
||||
this.currentPathValue = this.currentPathValue - 1;
|
||||
}
|
||||
|
@ -85,6 +94,8 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
this.currentPathValue = 0.0;
|
||||
}
|
||||
|
||||
var futurePosition = this.splineCurve3.getPointAt(this.currentPathValue);
|
||||
|
||||
// - - - - - - - - - - - - -
|
||||
// Ray trace from the future position.
|
||||
// - - - - - - - - -- - - - -
|
||||
|
@ -99,6 +110,11 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
);
|
||||
|
||||
var futureNormal = new THREE.Vector3(0, 1, 0);
|
||||
var futurePositionRayCasted = new THREE.Vector3(
|
||||
futurePosition.x,
|
||||
futurePosition.y,
|
||||
futurePosition.z
|
||||
);
|
||||
for(var m = 0, ml = this.trackThreeMeshArray.length; m < ml; ++m) {
|
||||
var intersect = ComponentPathFollowing_Three_Raycaster.intersectObject(
|
||||
this.trackThreeMeshArray[m]
|
||||
|
@ -106,6 +122,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
|
||||
if(intersect && intersect.length > 0) {
|
||||
futureNormal = intersect[0].face.normal;
|
||||
futurePositionRayCasted = intersect[0].point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +133,7 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
// - - - - - - - - -- - - - -
|
||||
|
||||
ComponentPathFollowing_Three_Raycaster.set(
|
||||
futurePosition,
|
||||
currentPosition,
|
||||
new THREE.Vector3(
|
||||
0,
|
||||
-1,
|
||||
|
@ -136,7 +153,8 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
}
|
||||
}
|
||||
|
||||
var avgNormal = currentNormal.add(this.pastNormal).add(futureNormal).normalize();
|
||||
//var avgNormal = currentNormal.add(this.pastNormal).add(futureNormal).normalize();
|
||||
var avgNormal = (this.pastNormal).add(futureNormal).normalize();
|
||||
this.pastNormal = futureNormal;
|
||||
|
||||
var matrix = new THREE.Matrix4().lookAt(
|
||||
|
@ -144,13 +162,43 @@ GameLib.D3.ComponentPathFollowing.prototype.onUpdate = function(
|
|||
futurePosition,
|
||||
avgNormal
|
||||
);
|
||||
|
||||
var quaternion = new THREE.Quaternion().setFromRotationMatrix(matrix);
|
||||
|
||||
var targetVector = new THREE.Vector3(
|
||||
this.maxOffset.x * this.offset.x,
|
||||
this.maxOffset.y * this.offset.y,
|
||||
this.maxOffset.z * this.offset.z
|
||||
);
|
||||
|
||||
var lerpedOffset = new THREE.Vector3(
|
||||
this.currentOffset.x,
|
||||
this.currentOffset.y,
|
||||
this.currentOffset.z
|
||||
).lerp(
|
||||
targetVector,
|
||||
(this.grain * this.steeringSpeed)
|
||||
);
|
||||
|
||||
this.currentOffset.x = lerpedOffset.x;
|
||||
this.currentOffset.y = lerpedOffset.y;
|
||||
this.currentOffset.z = lerpedOffset.z;
|
||||
|
||||
var transformedOffset = new THREE.Vector3(
|
||||
this.baseOffset.x + lerpedOffset.x,
|
||||
this.baseOffset.y + lerpedOffset.y,
|
||||
this.baseOffset.z + lerpedOffset.z
|
||||
).applyQuaternion(quaternion);
|
||||
|
||||
// apply to parent rigidbody instead of direclty to the mesh.
|
||||
parentEntity.position.x = futurePosition.x;
|
||||
parentEntity.position.y = futurePosition.y;
|
||||
parentEntity.position.z = futurePosition.z;
|
||||
/* parentEntity.position.x = futurePositionRayCasted.x + transformedOffset.x;
|
||||
parentEntity.position.y = futurePositionRayCasted.y + transformedOffset.y + this.parentEntity.mesh.geometry.boundingBox.y;
|
||||
parentEntity.position.z = futurePositionRayCasted.z + transformedOffset.z;
|
||||
*/
|
||||
|
||||
parentEntity.position.x = futurePosition.x + transformedOffset.x;
|
||||
parentEntity.position.y = futurePosition.y + transformedOffset.y;
|
||||
parentEntity.position.z = futurePosition.z + transformedOffset.z;
|
||||
|
||||
// update rotation
|
||||
parentEntity.quaternion.x = quaternion.x;
|
||||
|
|
Loading…
Reference in New Issue