added kinematic setting to rigid-body.

next up: spinning wheels, ai collision avoidance, onCollide-event
beta.r3js.org
polygonboutique 2016-11-30 10:31:44 +01:00
parent eaea4255df
commit 61ed31e517
2 changed files with 69 additions and 21 deletions

View File

@ -31,6 +31,14 @@ GameLib.D3.ComponentPathAI = function ComponentPathAI(
//#ifdef RUNTIME__ //#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 ////////////////////////// ///////////////////////// Methods to override //////////////////////////
GameLib.D3.ComponentPathAI.prototype.onUpdate = function( GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
deltaTime, deltaTime,
@ -42,27 +50,44 @@ GameLib.D3.ComponentPathAI.prototype.onUpdate = function(
var right = false; 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; this.pathFollowingComponent.direction = 1;
} else if (this.keyBackPressed){ } else if (backward && !forward) {
this.pathFollowingComponent.direction = -1; this.pathFollowingComponent.direction = -1;
} else { } else {
this.pathFollowingComponent.direction = 0; this.pathFollowingComponent.direction = 0;
} }
// left right if(left && !right) {
if (this.keyLeftPressed) { // Left [j]
this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.x = 0;
this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.y = 0;
this.pathFollowingComponent.offset.z = 1; this.pathFollowingComponent.offset.z = 1;
} else if (this.keyRightPressed) { // Right [l] } else if (right && !left) {
this.pathFollowingComponent.offset.x = 0; this.pathFollowingComponent.offset.x = 0;
this.pathFollowingComponent.offset.y = 0; this.pathFollowingComponent.offset.y = 0;
this.pathFollowingComponent.offset.z = -1; this.pathFollowingComponent.offset.z = -1;
}*/ } else {
this.pathFollowingComponent.offset.x = 0;
// tell path following component to move forward this.pathFollowingComponent.offset.y = 0;
this.pathFollowingComponent.direction = 1; this.pathFollowingComponent.offset.z = 0;
}
// - - -- - - - - -- - - - - - - - - - - - - - - // - - -- - - - - -- - - - - - - - - - - - - - -

View File

@ -16,6 +16,7 @@
* @param collisionFilterMask * @param collisionFilterMask
* @param fixedRotation * @param fixedRotation
* @param shape GameLib.D3.Shape * @param shape GameLib.D3.Shape
* @param kinematic Boolean
* @returns {GameLib.D3.Physics.RigidBody} * @returns {GameLib.D3.Physics.RigidBody}
* @constructor * @constructor
*/ */
@ -35,7 +36,8 @@ GameLib.D3.RigidBody = function(
collisionFilterGroup, collisionFilterGroup,
collisionFilterMask, collisionFilterMask,
fixedRotation, fixedRotation,
shape shape,
kinematic
) { ) {
this.id = GameLib.D3.Tools.RandomId(); this.id = GameLib.D3.Tools.RandomId();
this.position = position || new GameLib.D3.Vector3(); this.position = position || new GameLib.D3.Vector3();
@ -53,6 +55,7 @@ GameLib.D3.RigidBody = function(
this.collisionFilterMask = typeof collisionFilterMask == "undefined" ? 1 : collisionFilterMask; this.collisionFilterMask = typeof collisionFilterMask == "undefined" ? 1 : collisionFilterMask;
this.fixedRotation = typeof fixedRotation == "undefined" ? false : fixedRotation; this.fixedRotation = typeof fixedRotation == "undefined" ? false : fixedRotation;
this.shape = typeof shape == "undefined" ? null : shape; this.shape = typeof shape == "undefined" ? null : shape;
this.kinematic = kinematic || false;
this.engine = engine; this.engine = engine;
this.engine.isNotCannonThrow(); this.engine.isNotCannonThrow();
@ -150,19 +153,39 @@ GameLib.D3.RigidBody.prototype.onUpdate = function(
parentEntity parentEntity
) { ) {
if(parentEntity) { if(parentEntity) {
var quaternion = new THREE.Quaternion(); if (this.kinematic) {
quaternion.copy(this.instance.quaternion); // 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(); this.instance.quaternion.x = parentEntity.quaternion.x;
position.copy(this.instance.position); 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; this.instance.inertia.x = 0;
parentEntity.position.y = position.y; this.instance.inertia.y = 0;
parentEntity.position.z = position.z; this.instance.inertia.z = 0;
parentEntity.quaternion.x = quaternion.x; this.instance.velocity.x = 0;
parentEntity.quaternion.y = quaternion.y; this.instance.velocity.y = 0;
parentEntity.quaternion.z = quaternion.z; this.instance.velocity.z = 0;
parentEntity.quaternion.w = quaternion.w; } 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;
}
} }
}; };