[]关于3d的碰撞检测
这边的确看到射线应该碰撞到地形了,但是检测的结果一直是-1
相关代码:
const field: Laya.MeshSprite3D = this.scene.getChildByName("stadium").getChildByName("field") as Laya.MeshSprite3D;//拿到地板
const sprite3d1MeshCollider: Laya.MeshCollider = field.addComponent(Laya.MeshCollider) as Laya.MeshCollider;
sprite3d1MeshCollider.mesh = field.meshFilter.sharedMesh;
检测碰撞:
var rayOrigin: Laya.Vector3 = new Laya.Vector3(0, 0, 0); //射线原点
//根据角色位置计算射线原点
Laya.Vector3.add(this.ownerSprite.transform.position, new Laya.Vector3(speedX, 1, speedZ), rayOrigin);
//射线原点位置更新
this.ray.origin = rayOrigin;
//物理射线与碰撞器相交检测
Laya.Physics.rayCast(this.ray, this.outHitInfo, 0);
console.log("x:" + rayOrigin.x + " y:" + rayOrigin.y + " z" + rayOrigin.z)
this.phasorSpriter3D.begin(Laya.WebGLContext.LINES, LayaAir3D.camera);
this.phasorSpriter3D.line(this._linePos, this._color, this.ray.origin, this._color);
this.phasorSpriter3D.end();
console.log("碰撞检测" + this.outHitInfo.distance);//一直都是-1
要回复问题请先登录
1 个回复
Aar0n
赞同来自: