PhysicsImposter not in line with the mesh

Hello everyone,

I’m currently working on a racing game. I’m now trying to implement moving obstacles. I’m using AmmoJS for this, but the PhysicsImposter doesn’t seem to match my 3D model (see gif).

I’ve used this method for creating the PhysicsImposters
https://playground.babylonjs.com/#66PS52

Video of the result:

Code:

MakePhysicsObject (roadblock, scene) {

var physicsRoot = new Mesh('physicsRoot', scene)

roadblock.forEach((m, i) => {

  if (m.name.indexOf('cylinder') !== -1) {

    m.isVisible = false

    m.parent = physicsRoot

  }

})

roadblock.forEach((m, i) => {

  if (m.name === 'RoadBlock') {

    m.isVisible = true

    m.parent = physicsRoot

  }

})

physicsRoot.getChildMeshes().forEach((m) => {

  if (m.name.indexOf('cylinder') !== -1) {

    m.physicsImpostor = new PhysicsImpostor(m, PhysicsImpostor.CylinderImpostor, { mass: 0, friction: 0, restitution: 0 }, Game.Scene)

  }

})

physicsRoot.physicsImpostor = new PhysicsImpostor(physicsRoot, PhysicsImpostor.NoImpostor, { mass: 0, friction: 0, restitution: 0 }, Game.Scene)

return physicsRoot

}

Update () {

this.x += 0.01

this.movement = (Math.cos(this.x) / 50)

this.physicsRoot.position.y = this.physicsRoot.position.y + this.movement

}

The roadblock parameter is an array with the root, cylinders for the collision and the roadblock mesh. In the Update() I’m moving the object.

So as you can see, the PhysicsImpostor.CylinderImpostor doesn’t seem to be on the right spot. I was wondering if anyone knows what I might be overlooking?

hi @Ququta

Can you try to replicate the behavior in a playground? I’ll happy to take a look

Hi @Cedric .

This playground should show you the problem. I loaded in the model that I’m using in my example. As you can see, the model is levitating and the cube is intersecting the model on the wrong place. I don’t understand why.

https://playground.babylonjs.com/#66PS52#55

The pivot for the cylinder is not correctly placed. For the roadblock it’s at the bottom of the mesh. For the cylinder it’s not. Once scaled, this might explain the delta for collision.

1 Like

I’ve changed the pivot points to the center of each mesh. This solved the problem. I first tried changing all of the pivot points to the bottom of each mesh but that didn’t seem to work.

Thank you so much @Cedric