Hello,
I’m trying to change the shape of a physics body on the press of a button.
I’m using a physics aggregate to create the initial, shape, body etc.
I’ve read through this thread which has some additional details.
However, setting the aggregate’s shape to a newly created one seems to do nothing for me.
See this PG: https://playground.babylonjs.com/#4Y813L#38
I didn’t want to pollute the mentioned thread with this question, so I’m posting a new one.
Is there a way to get the shape to change dynamically?
cc @Cedric
See the bottom of this post:
Hi HiGreg,
I read your post (linked in the thread about scaling the shape), but it’s not working if I use an aggregate (see the PG). Am I missing something?
Setting the shape of the body again doesn’t seem to do anything in this case…
Try convert your code to using PhysicsBody and PhysicsShape instead (as detailed in that link). I had difficulty changing shape.density within the PhysicsAggregate. It might not be the same problem as yours, but PhysicsAggregate is just a convenience function for those moving from PhysicsImposter. I ran into one limitation, so I’d expect there to be others.
Yes that’s probably the best thing to do, I’ll get to converting my code tomorrow and see if it works.
I’m curious now Do you have a repro PG? It should be exactly the same between aggregate and body/shape usages.
I don’t think I have a repro.
I’m guessing the problem is in physicsAggregate.ts on line 165:
this.body.setMassProperties({ mass: this._options.mass });
Because the body’s user physics property mass is set by the aggregate, it always overrides the calculated (internal) one from the shape.
That’s my guess.