[LayaAir 2.0]我竟然被射线检测这个小功能给难了一天了

用过多个游戏引擎的我,射线检测的Demo都测试不通过,我对自己都无语了;场景中一个带碰撞体的箱子,从u3d中导入的场景,箱子没有添加layer,用的默认的default;死活检测不到;
camera: Laya.Camera;
ray = new Laya.Ray(Laya.Vector3._ZERO, Laya.Vector3._ZERO)
hitInfo:Laya.HitResult=new Laya.HitResult()
physics:Laya.PhysicsSimulation;
onAwake():void{
this.camera = this.owner.getChildByName("Main Camera") as Laya.Camera;
let scene: Laya.Scene3D = this.owner.scene as Laya.Scene3D;
 
this.physics=scene.physicsSimulation;
 
 
console.log("相机位置",(this.owner.getChildByName("Main Camera") as Laya.Sprite3D).transform.position)
}
onStart(): void {
 
 
Laya.stage.on(Laya.Event.MOUSE_DOWN,this,this.onMouseDownCb)
}
private onMouseDownCb(e:Laya.Event):void{
console.log("点击屏幕")
// console.log("相机位置",this.camera.)
this.camera.viewportPointToRay(new Laya.Vector2(Laya.stage.mouseX,Laya.stage.mouseY),this.ray)
if(this.physics.rayCast(this.ray,this.hitInfo)){
console.log("检测到了")
}
 
 
}
已邀请:

NothingSerious

赞同来自:

我真无语了,真的,一天了,

NothingSerious

赞同来自:

不说了,我哭 了,我被Vector3.ZERO这个亦是给坑了,把所有的Vector3.ZERO换成new Laya(0,0,0)就搞定了。。。

要回复问题请先

商务合作
商务合作