[SOLVED] halfExtents no effect when is modified by code

Hi!

Introduction:
I am working on a small project that allows me to create a little house for the countryside (they are small houses for watering, storing tools and etc…). The project aims to be a small assistant to help you build your own concrete house.
It is still in a very early phase.

Problem description
I have a problem that I have not been able to solve. I have a cube with a collision component and when I modify its sizes by code, the collision does not take effect. Example of code:

} else if (elementName === "inputZ") {
    this.entity.setLocalScale(this.entity.getLocalScale().x, this.entity.getLocalScale().y, value / 100);
}

// Apply new collision
var currentScale = this.entity.getLocalScale();
var newHalfExtents = new pc.Vec3(currentScale.x / 2, currentScale.y / 2, currentScale.z / 2);
this.entity.collision.halfExtents = newHalfExtents;

What am I doing wrong? I haven’t been able to figure out if I need to call another function to force it. I have tried removing and adding the component. Thanks! Here is a build if you want to take a look: GALANO - PLAYCANVAS

Thanks a lot!!

Jordi

The code is correct and should work. How do you verify that the new collision is correct?

Output your newHalfExtents to console and see if it has the correct scale. If the issue persists, you can create an empty project with a simple cube and change its collision half extents on a mouse click. The build links are useless for us, as we can’t see the code you use and we can’t debug it.

Hi Lexxik,

I have done so and I have been able to solve it. I created a script to draw the collision boundaries and it adapted correctly (it did so before). The problem I had when managing the raycast was that I forgot to update the bounding box and the initial dimensions were always taken into account.

Thank you very much for your help.

2 Likes