Weird behaviour on my ball

Sorry if this is a silly question, I am a newbie here, I have created a floor and added a ball on top of it, added impostor to both floor and ball. Floor impostor’s mass is 0 and ball impostor’s mass is 2 but here the problem is soon as I run the game ball goes up automatically and comes back. Any help on why is it happening?

//floor
scene.debugLayer.show();
scene.enablePhysics(new BABYLON.Vector3(0, -9.8, 0), new BABYLON.CannonJSPlugin());
camera = new BABYLON.FreeCamera(“camera”, new BABYLON.Vector3(0, 0, -10), scene);
floor = BABYLON.Mesh.CreateBox(“Box”,4.0,scene);
floor.position = new BABYLON.Vector3(0,-5,0);

var floorMaterial = new BABYLON.StandardMaterial("material", scene);
floorMaterial.emissiveColor = new BABYLON.Color3(1, 0.58, 0);
floor.material = floorMaterial;
floor.scaling = new BABYLON.Vector3(
  0.8, 1, -10
);
floor.renderingGroupId = 0;

floor.physicsImpostor = new BABYLON.PhysicsImpostor(
    floor,
    BABYLON.PhysicsImpostor.BoxImpostor,
    { mass: 0},
    scene);

//Sphere
var sphere = BABYLON.Mesh.CreateSphere(“sphere”, 12, 0.5, scene);
var marbleMaterial = new BABYLON.StandardMaterial(“ball”, scene);
marbleMaterial.diffuseColor = BABYLON.Color3.Green();
sphere.material = marbleMaterial;
sphere.position = new BABYLON.Vector3(0,-3.7,0);
sphere.renderingGroupId = 1;

sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, 
 BABYLON.PhysicsImpostor.SphereImpostor, { mass: 2 }, scene);

A working playground would be great. This way we can understand the problem much better.

Bit if I could guess, I would say that you create the ball inside the floor, and the physics engine simply ejects it :slight_smile:
Try playing with the sphere’s y position, and make sure it is high enough before starting the scene.

Thanks! that was brilliant. y position was the problem! I fixed it

1 Like