import Script3D = Laya.Script3D;
import Vector3 = Laya.Vector3;
import Sprite3D = Laya.Sprite3D;
/**炮弹基类 */
export default class ShellBase extends Script3D {
/**炮弹模型 */
protected _sprite3D:Sprite3D;
/**子弹的飞行速度 m/s*/
protected _speed:number = 5;
/**子弹的生命周期 ms*/
protected _lifeTime:number = 2000;
/**计时器 */
protected _timer:number = 0;
/**子弹的飞行方向 */
protected _direction:Vector3 = new Vector3(1, 1, 1);
/**最短距离 防穿透 单位m 一般该值 >= 飞行速度 / 最高帧数 */
protected _minDistance:number = 0.4;
constructor() {
super();
// if(direction) {
// Vector3.normalize(direction, this._direction);
// } else {
// console.error("direction 参数为null或未定义!");
// }
}
onStart() {
this._sprite3D = this.owner as Sprite3D;
}
onUpdate() {
let delta:number = Laya.timer.delta;
if( delta > 500) return;
this.move();
this._timer += delta;
if(this._timer >= this._lifeTime) {
this._sprite3D.destroy(); // 删除
}
}
/**移动 */
protected move(): void {
let translation: Vector3 = new Vector3();
Vector3.scale(this._direction, this._speed * Laya.timer.delta / 1000, translation);
this._sprite3D.transform.translate(translation, false);
}
}