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__
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;
}
// - - -- - - - - -- - - - - - - - - - - - - - -

View File

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