const { regClass, property } = Laya;
@regClass()
export class PlayerBullet extends Laya.Script {
declare owner: Laya.Sprite;
private _body: Laya.RigidBody;
onAwake(): void {
this._body = this.owner.getComponent(Laya.RigidBody);
}
/** 3D物理触发器事件与2D物理碰撞事件,开始碰撞时执行 */
onTriggerEnter(other: Laya.PhysicsColliderComponent | Laya.ColliderBase, self?: Laya.ColliderBase, contact?: any): void {
let info = contact.getHitInfo();
// 取消碰撞
contact.SetEnabled(false);
// 获取碰撞平面的法线
console.log(info.normal.x info.normal.y);
}
/** 3D物理触发器事件与2D物理碰撞事件,持续碰撞时执行 */
onTriggerStay(other: Laya.PhysicsColliderComponent | Laya.ColliderBase, self?: Laya.ColliderBase, contact?: any): void {
}
/** 3D物理触发器事件与2D物理碰撞事件,结束碰撞时执行 */
onTriggerExit(other: Laya.PhysicsColliderComponent | Laya.ColliderBase, self?: Laya.ColliderBase, contact?: any): void {
}
}
标签:Laya,碰撞,2D,contact,ColliderBase,LayaAir3,物理
From: https://www.cnblogs.com/kingBook/p/18325629