Enemy.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. import { _decorator, Node, Tween, Vec3, ProgressBar, UIOpacity, tween, Label, SkeletalAnimation, Animation, SphereCollider, CylinderCollider, MeshCollider, Collider} from 'cc';
  2. import { Game } from './Game';
  3. import { Player } from './Player';
  4. import { Utils } from '../utils/Utils';
  5. import { ResUtil } from '../utils/ResUtil';
  6. import MsgHints from '../utils/MsgHints';
  7. import { userIns } from '../data/UserData';
  8. import { autoBind } from '../extend/AutoBind';
  9. import { BaseExp } from '../core/base/BaseExp';
  10. import { GunBase } from '../items/base/GunBase';
  11. import { PoolManager } from '../core/manager/PoolManager';
  12. import { audioMgr } from '../core/manager/AudioManager';
  13. import { Constants } from '../data/Constants';
  14. const { ccclass, property } = _decorator;
  15. //部位类型
  16. export enum EPartType {
  17. head = "headCollider", //头部的碰撞体
  18. body = "bodyCollider", //身体的碰撞体
  19. tank = "tankCollider", //坦克的碰撞体
  20. shield = "shieldCollider", //盾的碰撞体
  21. sundries = "sundriesCollider", //杂物的碰撞体
  22. }
  23. //敌人动作类型
  24. export enum EAnimType {
  25. idle = "idle", //idle 待机状态
  26. die = "die", //die 死亡状态
  27. shoot = "shoot", //shoot 射击状态
  28. walk = "walk", //shoot 行走状态
  29. }
  30. //敌人类型枚举
  31. export enum EnemyType {
  32. SoldierPistol = 10001, // 大兵 - 普通士兵,使用手枪
  33. SniperSoldier = 10002, // 狙击兵 - 远程攻击单位,使用狙击枪
  34. ShieldSoldier = 10003, // 盾牌兵 - 高生命值防御单位,使用手枪和盾牌
  35. SnipeCaptain = 20001, // 狙击队长 - BOSS单位,使用强力狙击枪
  36. ScatterCaptain = 20002, // 机枪队长 - BOSS单位,使用高射速机关枪
  37. Tank = 20003, // 坦克 - BOSS单位,高生命值重型单位
  38. GeneralPistol = 20004 // 将军 - BOSS单位,综合型强力敌人
  39. }
  40. //武器类型枚举
  41. export enum WeaponType {
  42. Pistol = 1001, // 大兵手枪 将军手枪
  43. Sniper = 1002, // 狙击兵狙击枪 狙击队长狙击枪
  44. Shield = 1003, // 盾牌兵盾牌
  45. Scatter = 1005, // 机枪队长机关枪
  46. Tank_Pao = 1006, // 坦克
  47. }
  48. @ccclass('Enemy')
  49. export class Enemy extends BaseExp {
  50. @autoBind({type: ProgressBar,tooltip: "敌人血量"})
  51. public hpBar: ProgressBar = null!;
  52. @autoBind({type: Node,tooltip: "敌人受伤节点"})
  53. public hurt_num: Node = null!;
  54. @autoBind({type: Collider,tooltip: "敌人头部"})
  55. public headCollider: Collider = null!;
  56. @autoBind({type: Collider,tooltip: "敌人身体"})
  57. public bodyCollider: Collider = null!;
  58. @autoBind({type: Collider,tooltip: "坦克身体"})
  59. public tankCollider: Collider = null!;
  60. @autoBind({type: Node,tooltip: "坦克行走"})
  61. public tank_walk: Node = null!;
  62. @autoBind({type: Node,tooltip: "坦克射击"})
  63. public tank_shoot: Node = null!;
  64. //浓烟节点 只有军车的时候血量低于30%才会有
  65. public heavySmoke: Node = null;
  66. //敌人动画节点
  67. private skeletalAnim: SkeletalAnimation = null!;
  68. //根据敌人类型动态获取
  69. public enemyNode: Node = null!;
  70. public defaultSpeed: number = 0;
  71. public speed: number = 0;
  72. public isDead: boolean = false;
  73. //拥有的枪
  74. public gun: GunBase = null;
  75. //盾的节点
  76. public shieldNode: Node = null!;
  77. //拥有的盾可以使用的血量
  78. private _shieldHp: number = 0;
  79. public set shieldHp(value: number) {
  80. this._shieldHp = value;
  81. if(this._shieldHp <= 0){
  82. this.removeShield();
  83. }
  84. }
  85. public get shieldHp(): number {
  86. return this._shieldHp;
  87. }
  88. //当前金币的值
  89. public goldCount : number = 0;
  90. //玩家
  91. public player: Player = null!;
  92. //运动方向
  93. public moveDir: Vec3 = new Vec3();
  94. //设置的血量
  95. public curHP: number = 0;
  96. //敌人的原始血量
  97. public originHP: number = 0;
  98. //是否是没打死逃逸
  99. public escape: boolean = false;
  100. //敌人数据
  101. public data: any = null;
  102. //是否能锁定攻击对象了
  103. public isCanLock: boolean = false;
  104. //是否是在开火
  105. private isFire: boolean = false;
  106. //减血的时候是否是打到头
  107. public isShotHead: boolean = false;
  108. //敌人行走的路径
  109. public pathList: Array<Vec3> = [];
  110. //当前行走的位置
  111. public curMoveIndex: number = 0;
  112. //枪旋转角度
  113. public angle: number = 0;
  114. //新增警戒状态属性
  115. public isAlert: boolean = false;
  116. start() {
  117. this.hurt_num.active = false;
  118. }
  119. /**
  120. * 初始化数据
  121. */
  122. public async init(data: any){
  123. this.data = data;
  124. this.player = Game.I.player.getComponent(Player);
  125. const isTank:boolean = this.isTank();
  126. this.enemyNode = this.node.getChildByName(data.prb_name);
  127. if(isTank){
  128. this.tankCollider["args"] = [EPartType.tank,this];
  129. }else{
  130. this.headCollider["args"] = [EPartType.head,this];
  131. this.bodyCollider["args"] = [EPartType.body,this];
  132. this.skeletalAnim = this.enemyNode.getComponent(SkeletalAnimation);
  133. if(this.skeletalAnim){
  134. this.skeletalAnim?.play(EAnimType.idle);
  135. }
  136. }
  137. if(!this.enemyNode){
  138. MsgHints.show(`不存在:${JSON.stringify(data)}`)
  139. return;
  140. }
  141. this.isShotHead = false;
  142. this.isAlert = false;
  143. this.data = this.enemyData(data);
  144. this.isDead = false;
  145. this.escape = false;
  146. //设置血量
  147. this.curHP = this.originHP = data.hp;
  148. //敌人速度
  149. const s: number = data.speed * 3;
  150. this.speed = s;
  151. this.defaultSpeed = s;
  152. //设置枪的数据
  153. await this.createGun();
  154. //恢复初始雪条
  155. this.hpBar.progress = 1;
  156. this.hpBar.node.active = false;
  157. this.endFire();
  158. }
  159. /**
  160. * 把武器的参数带到敌人身上
  161. */
  162. public enemyData(data:any){
  163. if(!data)return;
  164. //主武器id
  165. const mainWeaponID:number = data.weapon_id_1;
  166. let hp: number = Utils.clone(data).hp;
  167. let gData:any = userIns.enemyWeaponTable.find(e=>e.gun_id == mainWeaponID);
  168. //副武器 盾上的血量
  169. const secondWeaponID:number = data.weapon_id_2;
  170. if(secondWeaponID != 0){
  171. let sData:any = userIns.enemyWeaponTable.find(e=>e.gun_id == secondWeaponID);
  172. if(sData && sData.hp > 0){
  173. data.hp += hp + sData.shield_hp;
  174. }
  175. }
  176. return Object.assign(data,gData);
  177. }
  178. /**
  179. * 创建英雄所拥有的枪
  180. */
  181. public async createGun(){
  182. this.removeGun();
  183. //敌人主武器
  184. let gunPos:Node = this.enemyNode.getChildByName("gun_pos");
  185. const mainWeaponID:number = this.data.weapon_id_1;
  186. let mData:any = userIns.enemyWeaponTable.find(e=>e.gun_id == mainWeaponID);
  187. let gunNode:Node = await ResUtil.loadRes(`enemy/gun/${mData.gun_prb_name}`,this.enemyNode) as Node;
  188. this.gun = gunNode.getComponent(GunBase);
  189. gunNode.active = true;
  190. gunNode.parent = gunPos.parent;
  191. gunNode.worldPosition = gunPos.worldPosition.clone();
  192. gunNode.eulerAngles = gunPos.eulerAngles.clone();
  193. this.gun.init(this.data,this);
  194. //敌人附武器
  195. const secondWeaponID:number = this.data.weapon_id_2;
  196. if(secondWeaponID != 0){
  197. let sData:any = userIns.enemyWeaponTable.find(e=>e.gun_id == secondWeaponID);
  198. let shieldNode:Node = await ResUtil.loadRes(`enemy/gun/${sData.gun_prb_name}`,this.enemyNode) as Node;
  199. let shieldPos:Node = this.enemyNode.getChildByName("shield_pos");
  200. shieldNode.active = true;
  201. shieldNode.parent = shieldPos.parent;
  202. shieldNode.worldPosition = shieldPos.worldPosition.clone();
  203. shieldNode.eulerAngles = shieldPos.eulerAngles.clone();
  204. shieldNode.children[0].getComponent(Collider)["args"] = [EPartType.shield,this];
  205. this.shieldNode = shieldNode;
  206. this.shieldHp = sData.shield_hp;
  207. }
  208. }
  209. /**
  210. * 移除枪回收武器的时候调用
  211. */
  212. public removeGun(){
  213. if(this.gun){
  214. this.gun.endFire();
  215. PoolManager.putNode(this.gun.node);
  216. this.gun = null;
  217. }
  218. this.isFire = false;
  219. this.removeShield();
  220. }
  221. /**
  222. * 移除盾
  223. */
  224. public removeShield(){
  225. if(this.shieldNode){
  226. PoolManager.putNode(this.shieldNode);
  227. this.shieldNode = null;
  228. }
  229. this._shieldHp = 0;
  230. }
  231. /**
  232. * 坦克冒浓烟
  233. */
  234. public tankHeavySmoke(){
  235. if(!this.isTank())return;
  236. if(this.heavySmoke)return;
  237. //血量过低30%冒浓烟
  238. if(this.curHP < this.data.hp * 0.3){
  239. ResUtil.playParticle(
  240. `effects/Prefabs/HeavySmoke`,
  241. 0,
  242. new Vec3(0.3,0.3,0.3),
  243. (heavySmoke) => {
  244. heavySmoke.parent = this.node.parent;
  245. heavySmoke.worldPosition = this.node.worldPosition.clone();
  246. heavySmoke.active = true;
  247. this.heavySmoke = heavySmoke;
  248. }
  249. );
  250. }
  251. }
  252. /**
  253. * 扣掉血
  254. * @param hp 血
  255. * @param pData 英雄数据
  256. * @param isHeadShot 是否是爆头
  257. */
  258. public subHP(hp: number, pData:any){
  259. if(Game.I.isPause
  260. ||this.isDead
  261. ||hp == null
  262. ||this.curHP <= 0){
  263. return;
  264. }
  265. this.hpBar.node.active = true;
  266. this.scheduleOnce(() => {
  267. if(this.hpBar){this.hpBar.node.active = false;}
  268. }, 0.8);
  269. this.curHP -= hp;
  270. this.tankHeavySmoke();
  271. //这种是伤害超级高直接死亡了
  272. if(hp > this.originHP){
  273. this.escape = false;
  274. this.showHurt(Utils.numberToString(hp));
  275. this.recycle()
  276. return;
  277. }
  278. //敌人死亡
  279. if(this.curHP <= 0 && !this.isDead){
  280. this.escape = false;
  281. this.recycle();
  282. }else{//进度条和单独扣血
  283. this.hpBar.progress = this.curHP / this.originHP;
  284. this.showHurt(Utils.numberToString(hp));
  285. }
  286. }
  287. /**
  288. * 开始敌人移动,面向玩家行走
  289. */
  290. public walk(points:Vec3[]) {
  291. if(points.length <= 0)return;
  292. this.curMoveIndex = 0;
  293. this.pathList = points;
  294. const time: number = 1 / this.data.speed;
  295. if(this.isTank()){
  296. this.tank_walk.active = true;
  297. this.tank_shoot.active = false;
  298. }else{
  299. ResUtil.playSkeletalAnim(this.skeletalAnim,EAnimType.walk,time);
  300. }
  301. this.updateDir(points[0].clone());
  302. }
  303. /**
  304. * 开始攻击
  305. */
  306. public beginFire(){
  307. if(this.player
  308. && !this.player.isDead
  309. && this.gun){
  310. this.isFire = true;
  311. this.gun.fire();
  312. }
  313. }
  314. /**
  315. * 结束攻击
  316. */
  317. public endFire(){
  318. this.gun.endFire();
  319. this.isFire = false;
  320. }
  321. /**
  322. * 回收敌人节点
  323. * @param f 是否是游戏进行中的正常回收 程序主动回收不参数个数统计和加分这些
  324. * @returns
  325. */
  326. public recycle(f: boolean = true){
  327. if(!this.node
  328. ||this.isDead){
  329. return;
  330. };
  331. if(f){//爆头击杀播放音效
  332. audioMgr.playOneShot(this.isShotHead ? Constants.audios.head_shot : Constants.audios.enemy_die);
  333. }
  334. this.removeGun();
  335. this.curHP = 0;
  336. //动画和回收时间
  337. let recycleTime: number = 2;
  338. if(!this.isTank()){
  339. ResUtil.playSkeletalAnim(this.skeletalAnim,EAnimType.die);
  340. }else{
  341. //坦克爆炸后生成爆炸特效
  342. ResUtil.playParticle(
  343. `effects/Prefabs/TankBoom`,
  344. 3,
  345. new Vec3(0.1,0.1,0.1),
  346. (particle) => {
  347. particle.parent = this.node.parent;
  348. particle.worldPosition = this.node.worldPosition.clone();
  349. particle.active = true;
  350. },
  351. () => {//爆炸完成后 回收浓烟
  352. if(this.heavySmoke && this.heavySmoke.parent){
  353. PoolManager.putNode(this.heavySmoke);
  354. this.heavySmoke = null;
  355. }
  356. }
  357. );
  358. recycleTime = 3;
  359. }
  360. this.isDead = true;
  361. this.hpBar.node.active = false;
  362. let death: Function = function(inite: boolean){
  363. this.node.getComponent(UIOpacity).opacity = 255;
  364. PoolManager.putNode(this.node);
  365. if(inite){
  366. Game.I.buildEnemys.subtractEnemy(this);
  367. }
  368. }.bind(this,f);
  369. this.unschedule(death)
  370. this.scheduleOnce(death,recycleTime);
  371. }
  372. /**
  373. * 展示敌人受到的伤害
  374. * @param hpStr
  375. */
  376. public showHurt(hpStr: string) {
  377. if(Game.I.isGameOver || this.isDead) return;
  378. //敌人流血特效
  379. ResUtil.playParticle(
  380. `effects/Prefabs/blood`,
  381. 1,
  382. new Vec3(0.2,0.2,0.2),
  383. (blood) => {
  384. blood.active = true;
  385. blood.parent = this.enemyNode.parent;
  386. const targetPos: Vec3 = this.enemyNode.worldPosition.clone();
  387. blood.worldPosition = new Vec3(targetPos.x,targetPos.y - 0.2,targetPos.z);
  388. }
  389. );
  390. //创建3D伤害数字
  391. const n = PoolManager.getNode(this.hurt_num, this.hurt_num.parent);
  392. let label:Label = n.getComponent(Label);
  393. label.color = Utils.hexColor(this.isShotHead ? "#F51414" : "#FFFFFF");
  394. label.string = hpStr;
  395. const oPos: Vec3 = this.hpBar.node.position.clone();
  396. n.position = oPos;
  397. const oScale: Vec3 = this.hurt_num.scale.clone();
  398. n.scale = oScale;
  399. n.getComponent(UIOpacity).opacity = 255;
  400. let bezier: Vec3[] = [];
  401. let num: number = 100;
  402. let forward = Utils.getRandomFloat(0, 1) > 0.5 ;
  403. if (forward) {
  404. bezier = [new Vec3(-(10/num)+oPos.x, (30/num)+oPos.y), new Vec3((-40/num)+oPos.x, (40/num)+oPos.y), new Vec3((-60/num)+oPos.x, oPos.y)];
  405. } else {
  406. bezier = [new Vec3((10/num)+oPos.x, (30/num)+oPos.y), new Vec3((40/num)+oPos.x, (40/num)+oPos.y), new Vec3((60/num)+oPos.x, oPos.y)];
  407. }
  408. n.position = new Vec3(bezier[2].x,bezier[2].y - (80/num),oPos.z);
  409. //贝塞尔曲线坐标函数
  410. let twoBezier = (t: number, p1: Vec3, cp: Vec3, p2: Vec3) => {
  411. let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
  412. let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
  413. return new Vec3(x, y, oPos.z);
  414. };
  415. let time: number = 0.65;
  416. tween(n)
  417. .parallel(
  418. tween()
  419. .to(time,{ scale: new Vec3(oScale.x * 0.4,oScale.y * 0.4,oScale.z * 0.4)}),
  420. tween()
  421. .to(time, bezier[2], {
  422. onUpdate: (target: Vec3, ratio: number) => {
  423. if(n.parent){
  424. const pos: Vec3 = twoBezier(ratio, bezier[0], bezier[1], bezier[2]);
  425. n.position = new Vec3(pos.x,pos.y - (80/num),oPos.z)
  426. }
  427. }
  428. })
  429. ).call(function(){
  430. tween(this.getComponent(UIOpacity))
  431. .to(0.15,{opacity: 0})
  432. .call(()=>{
  433. PoolManager.putNode(this);
  434. })
  435. .start();
  436. }.bind(n)).start();
  437. }
  438. /**
  439. * 计算是否命中玩家
  440. * @returns 返回命中状态
  441. */
  442. public calculateIsHit():boolean{
  443. let isGuaranteedHit: boolean = false;
  444. //获取射击的精准度
  445. const data:any = this.getDifficultyData();
  446. //生成0-1随机数用于命中判定 根据precision范围确定命中逻辑
  447. const random = Math.random();
  448. if(data.precision < 0){//负值100%不命中
  449. isGuaranteedHit = false;
  450. }else if(data.precision > 1) {//超过1 100%命中
  451. isGuaranteedHit = true;
  452. }else {//正常范围:随机判定
  453. isGuaranteedHit = random <= data.precision;
  454. }
  455. return isGuaranteedHit;
  456. }
  457. /**
  458. * 轻松杀敌增加游戏难度 只有单其他附加因素 例如:连杀等叠加状态 给敌人增加血
  459. */
  460. public addDiffHP(){
  461. if(!this.node
  462. ||this.isDead
  463. ||Game.I.isGameOver
  464. ||this.isDead){
  465. return;
  466. };
  467. const data:any = this.getDifficultyData();
  468. if(data.hp_ratio > 0){
  469. this.curHP += this.originHP * data.hp_ratio;
  470. }
  471. }
  472. /**
  473. * 敌人的射击的精准度 获得难度数据
  474. */
  475. public getDifficultyData(): any{
  476. //获取基础精准度(玩家预设值)
  477. const precision: number = userIns.getCurLevelData().precision;
  478. let basePrecision: number = precision;
  479. let diff:any = {
  480. precision: precision,//增加或减少的精准度 0-100%
  481. hp_ratio: 0,//增加或减少的血量 0-100%
  482. reaction_time: 0,//增加或减少的反应时间 0-100%
  483. }
  484. const each: number = Math.floor(Game.I.buildEnemys.getCurKillNum() / 3);
  485. //连杀3个敌人的次数 AI精准度增加1%
  486. diff.precision += each * 0.01;
  487. //连续通关3次以上才有的难度
  488. const lx_num: number = 3;
  489. if(userIns.passNum > lx_num){//1、连续通关 AI生命值增加15% 精准度增加5%
  490. diff.precision += userIns.passNum * 0.05;
  491. diff.precision = Math.min(basePrecision, 0.9);
  492. diff.hp_ratio += userIns.passNum * 0.15;
  493. diff.hp_ratio = Math.min(diff.hp_ratio, 1);
  494. }else{//2、通关失败 下一局 AI精准度下降5% AI反应时间增加0.5s
  495. diff.precision -= userIns.passNum * 0.05;
  496. diff.precision = Math.max(diff.precision, 0.1);
  497. diff.reaction_time += 0.5;
  498. }
  499. return diff;
  500. }
  501. /**
  502. * 更新敌人行走和变化方向
  503. */
  504. protected update(dt: number): void {
  505. if(Game.I.isGameOver
  506. || Game.I.isPause
  507. || !this.data
  508. || this.isDead) return;
  509. const targetPos = this.pathList[this.curMoveIndex];
  510. if(!targetPos)return;
  511. //保持速度调节逻辑
  512. dt = dt / Game.I.map.multiplySpeed();
  513. const currentPos = this.node.worldPosition.clone();
  514. const toTarget = targetPos.clone().subtract(currentPos);
  515. //敌人移动
  516. const moveDir = new Vec3();
  517. Vec3.subtract(moveDir, targetPos, currentPos);
  518. let distance:number = moveDir.length();
  519. //计算实际应移动距离
  520. const moveDistance = this.speed * dt;
  521. if(moveDistance > 0) {
  522. //使用标准化方向向量 + 实际移动距离
  523. const newPos = currentPos.add(toTarget.normalize().multiplyScalar(moveDistance));
  524. //添加移动平滑过渡 平滑系数 10-15比较好 值越大越平滑
  525. const smoothFactor = 20;
  526. this.node.worldPosition = Vec3.lerp(
  527. new Vec3(),
  528. currentPos,
  529. newPos,
  530. Math.min(1, dt * smoothFactor)
  531. );
  532. //更新方向
  533. const isLastPathPoint = this.curMoveIndex == this.pathList.length - 1;
  534. const dirTarget = isLastPathPoint
  535. ? Game.I.player.node.worldPosition
  536. : this.pathList[this.curMoveIndex + 1];
  537. this.updateDir(dirTarget);
  538. }
  539. //到达判断增加缓冲范围
  540. if(moveDistance > distance) {
  541. //从出生点走到第二个点就是外门第一个点就开门 并且门没有被打开
  542. if(this.curMoveIndex == 1
  543. && !Game.I.buildEnemys.isOpenDoor){
  544. Game.I.map.openDoor();
  545. Game.I.buildEnemys.isOpenDoor = true;
  546. }
  547. this.curMoveIndex++;
  548. if (this.curMoveIndex >= this.pathList.length) {
  549. this.beginFire();
  550. if(this.isTank()){
  551. this.tank_walk.active = false;
  552. this.tank_shoot.active = true;
  553. } else {
  554. ResUtil.playSkeletalAnim(this.skeletalAnim, EAnimType.shoot, this.data.atk_speed);
  555. }
  556. this.updateDir(Game.I.player.node.worldPosition);
  557. }
  558. }
  559. }
  560. /**
  561. * 更新敌人方向(根据目标坐标转向)
  562. * @param targetPos 目标坐标(路径点或玩家坐标)
  563. */
  564. public updateDir(targetPos: Vec3){
  565. const curPos = this.node.worldPosition.clone();
  566. //从目标位置指向当前位置
  567. const targetDir = Vec3.subtract(new Vec3(), curPos, targetPos);
  568. targetDir.normalize();
  569. //平滑插值转向 避免瞬间转向
  570. const currentDir = this.node.forward.clone();
  571. Vec3.slerp(currentDir, currentDir, targetDir, 0.15);
  572. this.node.forward = currentDir;
  573. }
  574. /**
  575. * 是否是坦克
  576. */
  577. public isTank():boolean{
  578. return this.data.id == EnemyType.Tank;
  579. }
  580. }