How do I get the world position of the collision bounding box center

I think I’m close but it’s not exactly correct. Seems like it’s offset about 90°

var CollisionShader = pc.createScript('collisionShader');

CollisionShader.attributes.add('collisionEntity', { type: 'entity' });

CollisionShader.prototype.initialize = function () {
    this.collision = this.collisionEntity.collision;
};

CollisionShader.prototype.update = function (dt) {
    let point = this.collisionEntity.getLocalPosition().clone().add(this.collision.linearOffset);
    let mat = this.collisionEntity.parent.getWorldTransform().clone()
    point = mat.transformPoint(point);
    this.app.drawWireSphere(point, 0.025, pc.Color.MAGENTA, 20, false);
};

Just use the collisionEntity world transform, not the parent.

1 Like

That’s correct. I played around with it but never got it working correctly so I thought I maybe need the parent. Turns out it’s way simpler and you don’t even need the collisionEntity position and can just use the collision offset and transform it to world coordinates:

CollisionShader.prototype.update = function (dt) {
    let center = this.collisionEntity.getWorldTransform().transformPoint(this.collision.linearOffset);
    this.app.drawWireSphere(center, 0.025, pc.Color.MAGENTA, 20, false);
};

Also no need to clone, as transformPoint never mutates the input vec.

1 Like