diff --git a/src/game-lib-component-path-ai.js b/src/game-lib-component-path-ai.js index 77db5a8..1a15165 100644 --- a/src/game-lib-component-path-ai.js +++ b/src/game-lib-component-path-ai.js @@ -31,6 +31,14 @@ GameLib.D3.ComponentPathAI = function ComponentPathAI( //#ifdef RUNTIME__ + +var componentPathAI_Raycast = function(from, to, settings, world) { + /* var raycastResult = new sys.physicsEngine.instance.RaycastResult(); + world.raycastClosest(from, to, settings, raycastResult); + return raycastResult;*/ +}; + + ///////////////////////// Methods to override ////////////////////////// GameLib.D3.ComponentPathAI.prototype.onUpdate = function( deltaTime, @@ -42,27 +50,44 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function( var right = false; - /*if (this.keyForwardPressed) { // Forward [i] + // Ray tracing part. + + var scaledSensorLengthOffset = this.pathFollowingComponent.currentSpeed; + + /*world.raycastClosest( + fromC, + + toC, + + {}, + + result + );*/ + + + + + if(forward && !backward) { this.pathFollowingComponent.direction = 1; - } else if (this.keyBackPressed){ + } else if (backward && !forward) { this.pathFollowingComponent.direction = -1; } else { this.pathFollowingComponent.direction = 0; } - // left right - if (this.keyLeftPressed) { // Left [j] + if(left && !right) { this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.z = 1; - } else if (this.keyRightPressed) { // Right [l] + } else if (right && !left) { this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.z = -1; - }*/ - - // tell path following component to move forward - this.pathFollowingComponent.direction = 1; + } else { + this.pathFollowingComponent.offset.x = 0; + this.pathFollowingComponent.offset.y = 0; + this.pathFollowingComponent.offset.z = 0; + } // - - -- - - - - -- - - - - - - - - - - - - - - diff --git a/src/game-lib-rigid-body.js b/src/game-lib-rigid-body.js index cc6dcef..a5510ac 100644 --- a/src/game-lib-rigid-body.js +++ b/src/game-lib-rigid-body.js @@ -16,6 +16,7 @@ * @param collisionFilterMask * @param fixedRotation * @param shape GameLib.D3.Shape + * @param kinematic Boolean * @returns {GameLib.D3.Physics.RigidBody} * @constructor */ @@ -35,7 +36,8 @@ GameLib.D3.RigidBody = function( collisionFilterGroup, collisionFilterMask, fixedRotation, - shape + shape, + kinematic ) { this.id = GameLib.D3.Tools.RandomId(); this.position = position || new GameLib.D3.Vector3(); @@ -53,6 +55,7 @@ GameLib.D3.RigidBody = function( this.collisionFilterMask = typeof collisionFilterMask == "undefined" ? 1 : collisionFilterMask; this.fixedRotation = typeof fixedRotation == "undefined" ? false : fixedRotation; this.shape = typeof shape == "undefined" ? null : shape; + this.kinematic = kinematic || false; this.engine = engine; this.engine.isNotCannonThrow(); @@ -150,19 +153,39 @@ GameLib.D3.RigidBody.prototype.onUpdate = function( parentEntity ) { if(parentEntity) { - var quaternion = new THREE.Quaternion(); - quaternion.copy(this.instance.quaternion); + if (this.kinematic) { + // reapply the entity's transform back to the rigid body, since it is kinematic + this.instance.position.x = parentEntity.position.x; + this.instance.position.y = parentEntity.position.y; + this.instance.position.z = parentEntity.position.z; - var position = new THREE.Vector3(); - position.copy(this.instance.position); + this.instance.quaternion.x = parentEntity.quaternion.x; + this.instance.quaternion.y = parentEntity.quaternion.y; + this.instance.quaternion.z = parentEntity.quaternion.z; + this.instance.quaternion.w = parentEntity.quaternion.w; - parentEntity.position.x = position.x; - parentEntity.position.y = position.y; - parentEntity.position.z = position.z; + this.instance.inertia.x = 0; + this.instance.inertia.y = 0; + this.instance.inertia.z = 0; - parentEntity.quaternion.x = quaternion.x; - parentEntity.quaternion.y = quaternion.y; - parentEntity.quaternion.z = quaternion.z; - parentEntity.quaternion.w = quaternion.w; + this.instance.velocity.x = 0; + this.instance.velocity.y = 0; + this.instance.velocity.z = 0; + } else { + var quaternion = new THREE.Quaternion(); + quaternion.copy(this.instance.quaternion); + + var position = new THREE.Vector3(); + position.copy(this.instance.position); + + parentEntity.position.x = position.x; + parentEntity.position.y = position.y; + parentEntity.position.z = position.z; + + parentEntity.quaternion.x = quaternion.x; + parentEntity.quaternion.y = quaternion.y; + parentEntity.quaternion.z = quaternion.z; + parentEntity.quaternion.w = quaternion.w; + } } }; \ No newline at end of file