PhysicsImpostor.CylinderImpostor type causes error (when used with new BABYLON.PhysicsImpostor)

Recently, using the PhysicsImpostor.CylinderImpostor type when creating a new BABYLON.PhysicsImpostor on a (Cylinder Shaped) Mesh causes a Javascript error. Other PhysicsImpostor types like BoxImpostor seem to work fine though on the same mesh. Apparantly some variable or property seems not to be defined any more compared to previous builds.

Here’s the code to reproduce it in the playground:

///////////////

    var width = 8;
    var depth = 16;

	scene.gravity = new BABYLON.Vector3(0, -9.81/4, 0);
	scene.collisionsEnabled = true;
	scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0)); // , new BABYLON.OimoJSPlugin());

    var mesh =
        BABYLON.MeshBuilder.CreateCylinder(
			"CylinderMesh",
            {
                diameter: Math.max(width, depth),
                height: Math.min(width, depth),
                tessellation: 4 * (Math.max(Math.round(Math.max(width, depth)/6.4), 1)),
            },
            scene);
	mesh.receiveShadows = false;
	mesh.freezeWorldMatrix();

	mesh.checkCollisions = true;
	mesh.physicsImpostor =
		new BABYLON.PhysicsImpostor(
			mesh,
			//BABYLON.PhysicsImpostor.BoxImpostor, // box impostor works
            BABYLON.PhysicsImpostor.CylinderImpostor, // broken, error: a is undefined
/*
TypeError: "a is undefined"
	_createShape https://preview.babylonjs.com/babylon.js:16:1505567
	generatePhysicsBody https://preview.babylonjs.com/babylon.js:16:1501452
	addImpostor https://preview.babylonjs.com/babylon.js:16:1498721
	_init https://preview.babylonjs.com/babylon.js:16:481951
	e https://preview.babylonjs.com/babylon.js:16:480506
*/
			{
				mass: 0,
				friction: 0.5*2, // 1.0 = friction of rubber on concrete
				restitution: 0.7/2, // 0.37 = restitution of tungsten/aluminum
			},
			scene);

/*
Similar error but then in my own web app:

TypeError: Cannot read property 'radiusTop' of undefined
    at e._createShape (babylon.js:16)
    at e.generatePhysicsBody (babylon.js:16)
    at e.addImpostor (babylon.js:16)
    at e._init (babylon.js:16)
    at new e (babylon.js:16)
    at new BABYLON.PhysicsImpostor
*/

///////////////

If you don’t enable physics on the scene, the code works fine also with CylinderImpostor type (but then you don’t have physics, so that doesn’t really solve the bug :slight_smile: )

Currently work is being carried out on the physics plugins and this bug has appeared in the preview version 4.0.0 alpha18 for the Cannon Plugin https://www.babylonjs-playground.com/#F15U0G#35 but It still works in the stable version 3.3 https://www.babylonjs-playground.com/indexStable.html#F15U0G#35

However this PG has a cylinder imposter working for Oimo Plugin https://www.babylonjs-playground.com/indexStable.html#F15U0G#35

Using

scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0));

Will default to Cannon.js

If you found the error while using Oimo would you please reproduce the error you found with the Oimo plugin in a playground.

1 Like

Hi @JohnK,

Thanks for your question.

I pasted the above code from my post right at the bottom of the default playground.

These are my results by modifying one line about the physics engine used:

scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0));

Defaults to Cannon.js creates the error.

scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0), new BABYLON.BABYLON.CannonJSPlugin());

Also creates the error.

scene.enablePhysics(new BABYLON.Vector3(0, -9.81/4, 0), new BABYLON.OimoJSPlugin());

Doesn’t create the error: works fine. :slight_smile:

So the bug seems to be related to the CannonJS interface only.

In my game I currently use the CannonJS plugin.

Does this answer your question?

Q

Yes. Thank you for confirming it is a Cannon issue only. This is a known issue.

Solved by the work @trevordev has just finished on the plugins correcting this and other bugs. New documentation available Use Forces - Babylon.js Documentation

1 Like