Mesh Collider Not Resizing When Entity Is Resized

Hello,

I am dynamically resizing a very basic room model, which has a mesh collider, upon a button click based on the height and width of a div element. The room resizes perfectly, but when I try to move around it(first person movement script), I abruptly come to a halt when there is obviously a lot of room left to cover. As far as I know, mesh colliders should resize based on the scale of the entity correct?

My code is as follows:-

Ui.prototype.initialize = function () {
    // create STYLE element
    let style = document.createElement('style');

    // append to head
    document.head.appendChild(style);
    style.innerHTML = this.css.resource || '';
    
    let bstyle = document.createElement('style');
    document.head.appendChild(bstyle);
    bstyle.innerHTML = this.Bcss.resource || '';
    
    // Add the HTML
    this.div = document.createElement('div');
    this.div.classList.add('container');
    this.div.innerHTML = this.html.resource || '';
    
    // append to body
    // can be appended somewhere else
    // it is recommended to have some container element
    // to prevent iOS problems of overfloating elements off the screen
    
    let self = this;
    
    document.body.appendChild(this.div);
    
    $("#CONV_BUTTON").click(function(){
        let width = $('#resizer').width();
        let height = $('#resizer').height();
        
        let room = self.app.root.findByName("RoomWithRoof");
        room.enabled = true;
        room.setLocalScale(width/10, 5, height/10);
        
        self.app.root.findByName("Player").enabled = true;
        self.app.root.findByName("camera").enabled = false;
        self.entity.enabled = false;
        
    });
    
};

Project can be found @ https://playcanvas.com/editor/scene/943414/. When launched, press “Convert To 3D” and then use WASD and mouse to move to repro the bug. Why is this happening?

Hi @DevilZ,

I think the collision component isn’t resizing the collider automatically each time you scale the entity. You will have to trigger a new generation.

Enabling/disabling the entity I think will do the trick.

It is initially disabled, and then enabled by code. Shouldn’t that be enough? Or do I need to do it one more time @Leonidas?

No, I think you just need to scale your entity before enabling it.

1 Like

Alright. Am trying now. Thanks.

Worked perfectly. Thanks again @Leonidas.

1 Like

@Leonidas, sorry I hadn’t noticed this issue before, but the problem seems to persist. I made the change you had mentioned. Now, it only happens toward the front of the room.

Are you sure these values are correct? It seems the entity/collider aren’t sized to the correct size.

Try replicating this with values in your editor by setting up an entity with that scale and a collider, to see if you will get the same behaviour.

The scale is a bit different now, it’s /55 instead of /10. I can’t exactly replicate it in the editor @Leonidas since it depends on the size of the div. The larger the div, the sooner I hit the barrier.

Not sure what other way there is to debug this.

Trying using Will’s script then to debug the rigid bodies:

1 Like

On the same note, I would recommend @yaustar playcanvas devtools, which includes Will’s visualization script. Pretty handy.

1 Like

We are looking into the issue. For now, model viewer starter kit should be fine as we try to debug the error.