我是通过触发trigger时 子弹发射射线 检测墙实现的, 大概代码:
let from = this.owner.transform.position;
let dir = new Laya.Vector3(this.dir.x, 0, this.dir.y);
let ray = new Laya.Ray(from, dir);
let HitResult = new Laya.HitResult();
let nv3;
scene.physicsSimulation.rayCast(ray, HitResult, 3, Consts.Coll_Bullet, Consts.Coll_Other);
if (HitResult.collider) {
nv3 = HitResult.normal;
nv3.y = 0;
let mid = 2 * Laya.Vector3.dot(dir, nv3);
Laya.Vector3.scale(nv3, mid, nv3);
Laya.Vector3.subtract(dir, nv3, dir);
console.log("反弹方向:",dir);
}
3 个回复
小小泽
赞同来自:
黑不黑
赞同来自:
黑不黑
赞同来自:
let from = this.owner.transform.position;
let dir = new Laya.Vector3(this.dir.x, 0, this.dir.y);
let ray = new Laya.Ray(from, dir);
let HitResult = new Laya.HitResult();
let nv3;
scene.physicsSimulation.rayCast(ray, HitResult, 3, Consts.Coll_Bullet, Consts.Coll_Other);
if (HitResult.collider) {
nv3 = HitResult.normal;
nv3.y = 0;
let mid = 2 * Laya.Vector3.dot(dir, nv3);
Laya.Vector3.scale(nv3, mid, nv3);
Laya.Vector3.subtract(dir, nv3, dir);
console.log("反弹方向:",dir);
}