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
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?