When i move my sphere it goes inside ground even i alredy pass ground.physics impostor and checkcollision now what issue pls reasolve it?

await BABYLON.SceneLoader.ImportMesh(
“”,
“images/”,
“road1.glb”,
scene,
function (meshes, particleSystem, skeletons, animation) {
ground = meshes[0];
ground.checkCollisions = true;
ground.id = “ground”;
ground.physicsImpostor = new PhysicsImpostor(
ground,
PhysicsImpostor.BoxImpostor,
{ mass: 0 },
scene
);
console.log(ground);
}
)

const sphere = BABYLON.MeshBuilder.CreateSphere(
“sphere”,
{ diameter: 1 },
scene
);
sphere.position.y = 0.2;
const pbr = new PBRMaterial(“pbr”, scene);
sphere.material = pbr;

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

Hi @dodiya Welcome to the community.
It would make debugging way easier if you could provide a PG.
in the mean time, check that meshes[0];is actually a mesh and not a transform node
also, if ground is at y = 0 and the sphere of diameter 1, at y = 0.2, then sphere collides with the road.

1 Like

sorry to say but how i know meshes[0] is actually mesh or not so how do i check

This is a forum, not a chat. People may not respond the minute you post a question.

You can that with the inspector

As said earlier, please provide a Playground or it will be difficult for the community to help you.

2 Likes

here is my inspector pls see this

pls check this

You need to provide a playground that works in order for the community to be able to help you.

Please check the resources available in the website Using External Assets In the Playground | Babylon.js Documentation (babylonjs.com) to properly import assets on the Playground.

1 Like

can you pls check code without that images if you find any mistake than pls check why sphere not move on groundmesh ? because i dont know how i upload that glb and images in playground

Again, this section may help - Using External Assets In the Playground | Babylon.js Documentation

1 Like

I assume this has already been done with this feedback

Read that a sphere of a diameter of 1 which center point accounted for position is half (= 0.5) when positioned at just 0.2 above colliding object (in this case the ground) IS already colliding at scene init. There might be other parts to it but this alone will create an issue. Position your sphere at say 2 and let it fall to the ground. Then see what happens next.

1 Like

const sphere = BABYLON.MeshBuilder.CreateSphere(
“sphere”,
{ diameter: 1 },
scene
);
sphere.position.y = 0.2;
sphere.position.z = -155;

when i do this then ball diectly goes on mass not stay in ground so what will i do now ?

Screenshot from 2024-01-22 11-24-00

is this metter for that ?

This will move the sphere a bit far away.
Did you start with a sample like https://playground.babylonjs.com/#Z8HTUN#1 and then add/change it to make it suit your needs? Start small and do multiple iterations.

yes but this for my custom postion so i dont think there any issue.

await BABYLON.SceneLoader.ImportMesh(
“”,
“images/”,
“road.glb”,
scene,
function (meshes, particleSystem, skeletons, animation) {
groundMesh = meshes[0];
console.log(groundMesh);
groundMesh.id = “groundMesh”;
groundMesh.name = “groundMesh”;
// groundMesh.position = new BABYLON.Vector3(0, 0, -100);
groundMesh.rotation = new BABYLON.Vector3(0, -300, 0);
// Inside the mesh loading callback
if (groundMesh) {
sphere.position.y =
groundMesh.getBoundingInfo().boundingBox.minimumWorld.y +
sphere.getBoundingInfo().boundingBox.maximumWorld.y / 2 +
1;
}

  groundMesh.physicsImpostor = new BABYLON.PhysicsImpostor(
    groundMesh,
    BABYLON.PhysicsImpostor.BoxImpostor,
    { mass: 0 },
    scene
  );
  groundMesh.physicsImpostor.registerOnPhysicsCollide(
    [sphere.physicsImpostor],
    detectCollition
  );
}

);
function detectCollition(impact) {
console.log(impact.object.id); //groundmesh
}

so i think mesh is actully mesh not a transparent node so why still sphere goes inside ground and goes mass

For the last time, we need a working Playground to be able to help you. Please remember that everyone’s time is valuable, so if you can’t dedicate your time to properly fix up your own code, why would the community have to fix it for you?

4 Likes