Weird Offset When Using addChild or setParent in Mesh

I’m creating a capsule mesh with a physics body, and I have a character model/mesh that I add as a child to that capsule. Despite using addChild or setParent, I constantly encounter this strange Y-axis offset. I can’t fit my character into the capsule properly. What could be the issue? I’m using version ^6.19.1.


(let [player (api/capsule :name "player" :height 2 :radius 0.3)]
    ;; SceneLoader.ImportMesh
    (api/import-mesh "character.glb" (fn [new-meshes _ _ anim-groups]
                                       (let [mesh (first new-meshes)]
                                         (j/call player :addChild mesh))))
    (m/assoc! player
              :checkCollisions true
              :visibility 0.3)

The origin (0,0,0) point of the sphere is the middle, so if the origin of the character is on its feet, it looks like they’re aligning as they should. You’d need to offset the character down on the y axis to align the feet with the bottom of the capsule

1 Like

Even though I add {:position.y -1}, I only get the correct result after refreshing the page a couple of times. As far as I can understand, SceneLoader.ImportMesh is not async; race condition could somehow be causing the offset problem?

ImportMesh indeed is not async, if you do anything with the model, it needs to be on the callback of ImportMesh. Or you could switch to awaiting the ImportMeshAsync