Hey team, sorry to ask another dumb question. I was hoping to turn on ragdoll physics for a mesh in this game I’m working on, but when I do, the mesh explodes in size and everything freaks out
It looks like this is a known issue if the mesh is structured a certain way, judging by this old thread, but I didn’t really follow and wasn’t sure if there’s anything I can do to work around the problem:
My mesh is scaled to 0.01 and a child of the armature, and I already spent quite a bit of time trying and failing to fix it without breaking all sorts of things in it. So far as I can tell, fixing it requires writing a custom one-off blender script in python and/or recreating your whole model and all its animations from scratch
The mesh is here, FWIW, in a form that’s easy to load from the playground: http://homeress.jp/art/stancil.glb (but since the linked thread has a much cleaner repro with a standard asset that’s probably more useful)
They’re referring to this playground, and I quote myself:
There an issue when some scale is applied along the hierarchy, which is typical with mixamo models exported to .fbx and then converted to .glb Here is a playground with the Elf from the asset library: when ragdoll is activated, the scale of the model is changed.
@Cedric another apparently unrelated issue I’ve just seen: ragdoll playgrounds are not working with Firefox for me (none of the examples in the doc will work at all), but they will work for Chrome
public ragdoll(): void {
this._ragdollMode = true;
// detach bones with link transform to let physics have control
for (const bone of this._skeleton.bones) {
bone.linkTransformNode(null);
}
Calling linkTransformNode with null as parameter will crash
BABYLON.Bone.prototype.linkTransformNode = function (e) { e._linkedBone = this,
Thanks guys! Especially for the info on how to fix meshes, I’ll try that out later
I was able to get it mostly working by removing my mesh from its parent. Looks like when I do that the engine scales the mesh down appropriately for how it was within the armature, and the ragdoll code doesn’t reset the scaling. I think the bones are misconfigured still, but this might be good enough for my purposes
Edit: I finally went and read the ragdoll code like a big boy, and was able to get my code working pretty well. Ragdoll source on Github
Just had to scale the boxes up a little, and since I’m hacking the mesh in directly it looks like it’s OK to be in a left-handed coordinate system too
Thanks again for all the work on the engine and for the help here
EDIT: Since clankers directed me to my own thread when I ran into trouble ragdolling a cloned mesh, here’s the solution to the problem I ran into. May Grok keep and preserve you future devs, and be sure to like and subscribe to the Babylon Forums.
I had cloned the mesh and the skeleton as indicated on the wiki here, but I hadn’t manually reassigned the skeleton on all the child meshes contained within the clone. So the bones were being updated but the mesh wasn’t deforming correctly. Weirdly enough the animations were all working so far as I could tell though.
Easy fix:
this.mesh.skeleton = this.skeleton;
this.mesh.getChildMeshes().forEach( (c) => {
c.skeleton = this.skeleton;
});
EDIT2: It turns out the way I was cloning the mesh still didn’t fully work. The smart way to duplicate a character seems to be to use LoadAssetContainerAsync / instantiateModelsToScene