[]射线一直无法获取物体
添加物体:
var qb_pet = scene.addChild(Laya.Sprite3D.load("./test.lh"));
qb_pet.once(Laya.Event.HIERARCHY_LOADED, this, function(){
qb_pet.addComponent(Laya.SphereCollider);
});
设置射线: Laya.timer.frameLoop(1, null, checkHit);
var hit = new Laya.RaycastHit();
var point = new Laya.Vector2();
var ray = new Laya.Ray(new Laya.Vector3(0, 0, 0), new Laya.Vector3(0, 0, 0));
function checkHit() {
//从屏幕空间生成射线
point.elements[0] = Laya.MouseManager.instance.mouseX;
point.elements[1] = Laya.MouseManager.instance.mouseY;
camera.viewportPointToRay(point, ray);
//射线检测获取所有检测碰撞到的物体
Laya.Physics.rayCast(ray, hit, 1000);
}
Laya.stage.on(Laya.Event.MOUSE_UP, this, function () {
var str = "";
if (!hit.sprite3D) {
str = "点击选取的几何体";
}else{
str = hit.sprite3D.name + " ";
}
console.log(str);
});
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
cuixueying
赞同来自: