[SOLVED] How to change size of a collision box in code?

Hello,
I can’t find a way how to change size of a collision box of an entity in code.

I can add collision box to entity with:

let collision = entity.addComponent("collision", { type: "box" });

or I can specify box’s size:

let collision = entity.addComponent("collision", { type: "box", halfExtents: [5, 0.5, 4] });

But I’m unable to change the size of the box after is has been created. The following code doesn’t work:

collision.halfExtents.set(2, 0.5, 2); // This change values of the property but internally the collision box has still the original dimension

The strange thing is that if the collision type is sphere, I can change the radius of the sphere after is has been created without a problem.

1 Like

Ok, I’ve just solved it :slight_smile:

collision.halfExtents = new pc.Vec3(1, 1, 1);
4 Likes