Best way to detect 'out of bounds'?

Hi there, I need a smart way to detect when model gets out of collision bounds
By getting out I mean: When it just starts touching the imaginary collision wall

What I did so far: Calculating bounding box for all mesh instances


Hi @Newbie_Coder,

You can use the intersects method by looping through your mesh instances aabb and testing it against the boundary bounding box.

As soon as it touches that wall it will return true:

1 Like

I’ve built a very simple scene to test it out, small box is moved inside big box, the state changes only when small box is fully outside the other (touching the wall is not enough for state to change)

aabb = this.entity.render._meshInstances[0]._aabb;

otherEntity ='Small');
otheraabb = otherEntity.render._meshInstances[0]._aabb;


Final solution

aabb = this.entity.render._meshInstances[0]._aabb;

otherEntity ='Model');

otheraabb = new pc.BoundingBox();

// once model is available (if preloaded, then straight away)
var meshes = otherEntity.model.model.meshInstances;
if (meshes.length) {
    for(var i = 1; i < meshes.length; i++)

boundX = aabb.halfExtents.x - otheraabb.halfExtents.x;
boundY = aabb.halfExtents.y - otheraabb.halfExtents.y;
boundZ = aabb.halfExtents.z - otheraabb.halfExtents.z;
offsetX =;
offsetY =;
offsetZ =;

var mainBound = this.entity.getPosition();

if (Math.abs(mainBound.z - offsetZ) > boundZ) {
    console.log('Exceeds on Z');

if (Math.abs(mainBound.y - offsetY) > boundY) {
    console.log('Exceeds on Y');

if (Math.abs(mainBound.x - offsetX) > boundX) {
    console.log('Exceeds on X');

Any way to get aabb of a blank entity that has collision element only? Debug draw displays it with no problem

So, for a blank entity with a box collision component you can use a proxy aabb. Example:

const aabb = new pc.BoundingBox();;
1 Like