Any way to resize a CylinderImpostor?

Hello. I know the box impostor can be resized with dimensions provided in the options argument. Is there anything similar but for a CylinderImpostor? It seems to automatically size itself to the mesh, but is a bit too wide unfortunately. I am using AmmoJS

I did try the meshImpostor as well… seemed awesome but it might be a bit too heavy for performance.

I am creating it like this:

this.soldier.physicsImpostor = new PhysicsImpostor(
    this.soldier,
    PhysicsImpostor.CylinderImpostor,
    { mass: 90 },
    this.scene,
);
this.soldier.physicsImpostor.setDeltaPosition(
    new Vector3(0, -95, 0),
);

Here is how it looks in the physics/collision debugger:

sc1
sc2

Thanks for the help!

Lets summon @RaananW into the thread :slight_smile:

Not sure about PhysicsImposter, but you might consider migrating to Havok physics (i.e. physics V2). With Havok, you can use PhysicsAggregate (a convenience function designed to help migrate from Physics Imposter), or generate PhysicsBody and PhysicsShape directly. Here are some tips, including scaling, on using PhysicsBody and PhysicsShape in Havok. Scaling a mesh in V2 (aka Havok) requires regenerating the PhysicShape.

Instead of automatically generating the cylinder then scaling, you might consider calculating the radius and height from mesh points. You could include only the desired submeshes and/or children meshes in the calculation. Be sure to use mesh points in world space.

2 Likes

Perfect answer, thanks a lot @HiGreg .

To give an exact answer regarding the cylinderimpostor - it takes the metadata from the mesh itself. It uses the mesh’s bounding box to do that. The code can be found here - Babylon.js/packages/dev/core/src/Physics/v1/Plugins/ammoJSPlugin.ts at master · BabylonJS/Babylon.js (github.com)

If the bounding box has changed you will need to create a new impostor. This is for physics V1 (i.e. ammo). Havok is much more stable and, TBH, better implemented :slight_smile: