Hello, according to this house plan, I want to hide the wall that the camera sees, but I am getting an error. how can i do?
I wrote the following sample code in the playground below.
// Function to determine the closest wall based on raycast
function getClosestWall(cameraPosition) {
const ray = new BABYLON.Ray(cameraPosition, camera.direction); // Create a ray from camera position
const pickInfo = scene.pickWithRay(ray); // Perform raycast
if (pickInfo.pickedMesh && pickInfo.pickedMesh instanceof wall) { // Check if it hit a wall
return pickInfo.pickedMesh; // Return the closest wall
} else {
return null; // No wall hit
}
}
scene.registerBeforeRender(() => { // Update on every frame
const closestWall = getClosestWall(camera.position); // Get the closest wall
if (closestWall) {
closestWall.isVisible = false; // Hide the closest wall for this frame
} else {
// Make all walls visible if no wall is hit
for (const wall of walls) {
wall.isVisible = true;
}
}
});
I’m sorry for my bad english. What I mean is, if a ray was drawn from the camera and the wall it hit was invisible. That’s what I meant. I hope I could explain it this time.