I use pickWithRay to monitor whether the mesh is close to ground. When I return the predicate directly to true, I expect to return the first mesh, but it seems to have no effect in reality
private _floorRaycast(offsetx: number, offsetz: number, raycastlen: number): BABYLON.Vector3 {
//position the raycast from bottom center of mesh
let raycastFloorPos = new BABYLON.Vector3(this._player?.position.x ?? 0 + offsetx, this._player?.position.y ?? 0 + 0.5, this._player?.position.z ?? 0 + offsetz);
let ray = new BABYLON.Ray(raycastFloorPos, BABYLON.Vector3.Up().scale(-1), raycastlen, 0.1);
const t = Date.now()
let pickMesh = null
//defined which type of meshes should be pickable
let cb = (mesh) => {
console.log(mesh)
return true
}
console.log("start")
let pick = this._scene.pickWithRay(ray, cb);
console.log(pick, "pick")
console.log("end")
if (pick?.hit) { //grounded
return pick.pickedPoint!;
} else { //not grounded
return BABYLON.Vector3.Zero();
}
}
//raycast from the center of the player to check for whether player is grounded
private _isGrounded(): boolean {
// console.log(this.num++,"_isGrounded")
if (this._floorRaycast(0, 0, .6).equals(BABYLON.Vector3.Zero())) {
return false;
} else {
return true;
}
}```
![image|690x254](upload://58xB2ctm0Zb3b6ofGdODe55znds.png)