Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/framework/components/collision/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CollisionBoxSystemImpl extends CollisionSystemImpl {
createPhysicalShape(entity, component) {
if (typeof Ammo !== 'undefined') {
const he = component.halfExtents;
const ammoHe = new Ammo.btVector3(he ? he.x : 0.5, he ? he.y : 0.5, he ? he.z : 0.5);
const ammoHe = new Ammo.btVector3(he.x, he.y, he.z);
const shape = new Ammo.btBoxShape(ammoHe);
Ammo.destroy(ammoHe);
return shape;
Expand All @@ -204,9 +204,9 @@ class CollisionSphereSystemImpl extends CollisionSystemImpl {
// Capsule Collision System
class CollisionCapsuleSystemImpl extends CollisionSystemImpl {
createPhysicalShape(entity, component) {
const axis = component.axis ?? 1;
const radius = component.radius ?? 0.5;
const height = Math.max((component.height ?? 2) - 2 * radius, 0);
const axis = component.axis;
const radius = component.radius;
const height = Math.max(component.height - 2 * radius, 0);

let shape = null;

Expand All @@ -231,9 +231,9 @@ class CollisionCapsuleSystemImpl extends CollisionSystemImpl {
// Cylinder Collision System
class CollisionCylinderSystemImpl extends CollisionSystemImpl {
createPhysicalShape(entity, component) {
const axis = component.axis ?? 1;
const radius = component.radius ?? 0.5;
const height = component.height ?? 1;
const axis = component.axis;
const radius = component.radius;
const height = component.height;

let halfExtents = null;
let shape = null;
Expand Down Expand Up @@ -266,9 +266,9 @@ class CollisionCylinderSystemImpl extends CollisionSystemImpl {
// Cone Collision System
class CollisionConeSystemImpl extends CollisionSystemImpl {
createPhysicalShape(entity, component) {
const axis = component.axis ?? 1;
const radius = component.radius ?? 0.5;
const height = component.height ?? 1;
const axis = component.axis;
const radius = component.radius;
const height = component.height;

let shape = null;

Expand Down
32 changes: 5 additions & 27 deletions src/framework/components/collision/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,7 @@ class Trigger {

const mass = 1;

const component = this.component;
if (component) {
const bodyPos = component.getShapePosition();
const bodyRot = component.getShapeRotation();
_ammoVec1.setValue(bodyPos.x, bodyPos.y, bodyPos.z);
_ammoQuat.setValue(bodyRot.x, bodyRot.y, bodyRot.z, bodyRot.w);
} else {
const pos = entity.getPosition();
const rot = entity.getRotation();
_ammoVec1.setValue(pos.x, pos.y, pos.z);
_ammoQuat.setValue(rot.x, rot.y, rot.z, rot.w);
}

_ammoTransform.setOrigin(_ammoVec1);
_ammoTransform.setRotation(_ammoQuat);
this._getEntityTransform(_ammoTransform);

const body = this.app.systems.rigidbody.createBody(mass, shape, _ammoTransform);

Expand Down Expand Up @@ -89,18 +75,10 @@ class Trigger {
}

_getEntityTransform(transform) {
const component = this.component;
if (component) {
const bodyPos = component.getShapePosition();
const bodyRot = component.getShapeRotation();
_ammoVec1.setValue(bodyPos.x, bodyPos.y, bodyPos.z);
_ammoQuat.setValue(bodyRot.x, bodyRot.y, bodyRot.z, bodyRot.w);
} else {
const pos = this.entity.getPosition();
const rot = this.entity.getRotation();
_ammoVec1.setValue(pos.x, pos.y, pos.z);
_ammoQuat.setValue(rot.x, rot.y, rot.z, rot.w);
}
const bodyPos = this.component.getShapePosition();
const bodyRot = this.component.getShapeRotation();
_ammoVec1.setValue(bodyPos.x, bodyPos.y, bodyPos.z);
_ammoQuat.setValue(bodyRot.x, bodyRot.y, bodyRot.z, bodyRot.w);

transform.setOrigin(_ammoVec1);
transform.setRotation(_ammoQuat);
Expand Down