[0]发射射线检测不到,物体有包围盒
发射射线,但是检测不到物体,物体确定加包围盒了
onStart(): void {
var self = this;
this.hitResult=new Laya.HitResult();
Laya.Scene3D.load("res/LayaScene_game/Conventional/game.ls",Laya.Handler.create(null,function(scene3d){
// HelperApp.a = scene3d;
//加载完成获取到了Scene3d
scene3d.name = 'good';
self.owner.addChild(scene3d);
var lv = scene3d.getChildByName("--- GAMEPLAY ---").getChildByName("Levels Parent");
// Laya.Sprite3D.load("res/prefabs/Conventional/prefabs.lh", Laya.Handler.create(null, function (sp) {
// lv.addChild(sp);
// console.log("添加预制体");
// }));
self.camera = scene3d.getChildByName("--- ENVIRONEMENT ---").getChildByName("Main Camera");
self.scene = scene3d;
}));
this._ray = new Laya.Ray(new Laya.Vector3(0, 0, 0), new Laya.Vector3(0, 0, 0));
}
onMouseDown() {
this.point.x = Laya.stage.mouseX;
this.point.y = Laya.stage.mouseX;
//产生射线
this.camera.viewportPointToRay(this.point,this._ray);
//拿到射线碰撞的物体
this.scene.physicsSimulation.rayCast(this._ray,this.hitResult);
//如果碰撞到物体
console.log("1111111111",this.hitResult);
// if (this.outs.length != 0)
// {
// console.log("碰撞到物体",this,this.outs[0]);
// }
}
onStart(): void {
var self = this;
this.hitResult=new Laya.HitResult();
Laya.Scene3D.load("res/LayaScene_game/Conventional/game.ls",Laya.Handler.create(null,function(scene3d){
// HelperApp.a = scene3d;
//加载完成获取到了Scene3d
scene3d.name = 'good';
self.owner.addChild(scene3d);
var lv = scene3d.getChildByName("--- GAMEPLAY ---").getChildByName("Levels Parent");
// Laya.Sprite3D.load("res/prefabs/Conventional/prefabs.lh", Laya.Handler.create(null, function (sp) {
// lv.addChild(sp);
// console.log("添加预制体");
// }));
self.camera = scene3d.getChildByName("--- ENVIRONEMENT ---").getChildByName("Main Camera");
self.scene = scene3d;
}));
this._ray = new Laya.Ray(new Laya.Vector3(0, 0, 0), new Laya.Vector3(0, 0, 0));
}
onMouseDown() {
this.point.x = Laya.stage.mouseX;
this.point.y = Laya.stage.mouseX;
//产生射线
this.camera.viewportPointToRay(this.point,this._ray);
//拿到射线碰撞的物体
this.scene.physicsSimulation.rayCast(this._ray,this.hitResult);
//如果碰撞到物体
console.log("1111111111",this.hitResult);
// if (this.outs.length != 0)
// {
// console.log("碰撞到物体",this,this.outs[0]);
// }
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Laya_Fred
赞同来自: