Kziwws 4 روز پیش
والد
کامیت
ac0708c67a

+ 26 - 6
assets/scripts/game/Enemy.ts

@@ -1,4 +1,4 @@
-import { _decorator, Node, Tween, Vec3, ProgressBar, UIOpacity, tween, Label, SkeletalAnimation, Animation, SphereCollider, CylinderCollider, MeshCollider, Collider} from 'cc';
+import { _decorator, Node, Tween, Vec3, ProgressBar, UIOpacity, tween, Label, SkeletalAnimation, Animation, SphereCollider, CylinderCollider, MeshCollider, Collider, PhysicsRayResult} from 'cc';
 import { Game } from './Game';
 import { Player } from './Player';
 import { Utils } from '../utils/Utils';
@@ -123,6 +123,8 @@ export class Enemy extends BaseExp {
     public angle: number = 0;
     //新增警戒状态属性
     public isAlert: boolean = false;
+    //子弹击中的的位置
+    public raycastResults:PhysicsRayResult = null;
 
     start() {
         this.hurt_num.active = false;
@@ -167,7 +169,6 @@ export class Enemy extends BaseExp {
         this.hpBar.progress = 1;
         this.hpBar.node.active = false;
         this.endFire();  
-        this.schedule(this.updateAAAA.bind(this),0.016199);
     }
 
     /**
@@ -401,6 +402,24 @@ export class Enemy extends BaseExp {
      */
     public showHurt(hpStr: string) {
         if(Game.I.isGameOver || this.isDead) return;
+        //敌人流血特效
+        if(this.raycastResults){
+            ResUtil.playParticle(
+                `effects/Prefabs/blood`, 
+                1, 
+                new Vec3(0.2,0.2,0.2),
+                (blood) => { 
+                    blood.active = true;
+                    blood.setParent(this.raycastResults.collider.node.parent);
+                    blood.worldPosition = this.raycastResults.hitPoint.add(this.raycastResults.hitNormal.multiplyScalar(0.01));
+                    blood.forward = this.raycastResults.hitNormal.multiplyScalar(-1);
+                    /*blood.active = true;
+                    blood.parent = this.enemyNode.parent; 
+                    const targetPos: Vec3 = this.enemyNode.worldPosition.clone();
+                    blood.worldPosition = new Vec3(targetPos.x,targetPos.y - 0.2,targetPos.z);*/
+                }
+            );
+        }
         //创建3D伤害数字
         const n = PoolManager.getNode(this.hurt_num, this.hurt_num.parent);
         let label:Label = n.getComponent(Label);
@@ -520,7 +539,7 @@ export class Enemy extends BaseExp {
     /**
      * 更新敌人行走和变化方向
      */
-    protected updateAAAA(dt: number): void {
+    protected update(dt: number): void {
         if(Game.I.isGameOver 
             || Game.I.isPause 
             || !this.data 
@@ -528,7 +547,7 @@ export class Enemy extends BaseExp {
         const targetPos = this.pathList[this.curMoveIndex];
         if(!targetPos)return;
         //保持速度调节逻辑
-        dt = dt / Game.I.map.multiplySpeed();
+        //dt = dt / Game.I.map.multiplySpeed();
         const currentPos = this.node.worldPosition.clone();
         const toTarget = targetPos.clone().subtract(currentPos);
         //敌人移动
@@ -540,14 +559,15 @@ export class Enemy extends BaseExp {
         if(moveDistance > 0) {
             //使用标准化方向向量 + 实际移动距离
             const newPos = currentPos.add(toTarget.normalize().multiplyScalar(moveDistance));
+            this.node.worldPosition = newPos;
             //添加移动平滑过渡 平滑系数 10-15比较好 值越大越平滑
-            const smoothFactor = 20;
+            /*const smoothFactor = 10;
             this.node.worldPosition = Vec3.lerp(
                 new Vec3(),
                 currentPos,
                 newPos,
                 Math.min(1, dt * smoothFactor)
-            );
+            );*/
             //更新方向
             const isLastPathPoint = this.curMoveIndex == this.pathList.length - 1;
             const dirTarget = isLastPathPoint 

+ 1 - 19
assets/scripts/items/base/BulletBase.ts

@@ -1,7 +1,6 @@
-import { _decorator, Component, js,Node, PhysicsRayResult, Vec3 } from 'cc';
+import { _decorator, Component,Node, PhysicsRayResult, Vec3 } from 'cc';
 import { GunBase } from './GunBase';
 import { PoolManager } from '../../core/manager/PoolManager';
-import { Enemy } from '../../game/Enemy';
 import { ResUtil } from '../../utils/ResUtil';
 import { Game } from '../../game/Game';
 
@@ -24,23 +23,6 @@ export class BulletBase extends Component {
         this.scheduleOnce(this.autoRecycle.bind(this),this.recycleTime);
     }
 
-    /**
-     * 敌人流血特效
-     */
-    public enemyBlood(e:PhysicsRayResult){
-        ResUtil.playParticle(
-            `effects/Prefabs/blood`, 
-            1, 
-            new Vec3(0.02,0.02,0.02),
-            (blood) => { 
-                blood.active = true;
-                blood.setParent(e.collider.node.parent);
-                blood.worldPosition = e.hitPoint.add(e.hitNormal.multiplyScalar(0.01));
-                blood.forward = e.hitNormal.multiplyScalar(-1);
-            }
-        );
-    }
-
     /**
      * 加入射击中的效果
      * @param e 碰撞到的结果

+ 2 - 4
assets/scripts/items/player/Bullet1.ts

@@ -5,7 +5,6 @@ import { BulletBase } from '../base/BulletBase';
 import { Enemy, EPartType } from '../../game/Enemy';
 import { PoolManager } from '../../core/manager/PoolManager';
 import { Sundries } from '../../game/Sundries';
-import { ResUtil } from '../../utils/ResUtil';
 const { ccclass, property } = _decorator;
 
 //玩家所用子弹 98k m24 awm BarrettM82A1 重狙子弹
@@ -126,9 +125,8 @@ export class Bullet1 extends BulletBase {
                            e.subHP(attack,this.gunBase.data);
                         }
                     }else{
-                        e.subHP(attack,this.gunBase.data);
-                        //敌人流血特效
-                        this.enemyBlood(targetResult);
+                        e.raycastResults = targetResult;
+                        e.subHP(attack,this.gunBase.data); 
                     }
                 }else if(cls instanceof Sundries){
                     const sundrie: Sundries = cls as Sundries;

+ 1 - 2
assets/scripts/items/player/Bullet2.ts

@@ -124,9 +124,8 @@ export class Bullet2 extends BulletBase {
                            e.subHP(attack,this.gunBase.data);
                         }
                     }else{
+                        e.raycastResults = targetResult;
                         e.subHP(attack,this.gunBase.data);
-                        //敌人流血特效
-                        this.enemyBlood(targetResult);
                     }
                 }else if(cls instanceof Sundries){
                     const sundrie: Sundries = cls as Sundries;

+ 2 - 3
assets/scripts/items/player/Bullet3.ts

@@ -2,7 +2,6 @@ import { _decorator, Vec3,Node, geometry, PhysicsSystem, PhysicsRayResult} from
 import { PoolManager } from '../../core/manager/PoolManager';
 import { Game } from '../../game/Game';
 import { Enemy, EPartType } from '../../game/Enemy';
-import { Gun3 } from './Gun3';
 import { BulletBase } from '../base/BulletBase';
 import { GunBase } from '../base/GunBase';
 import { Sundries } from '../../game/Sundries';
@@ -50,6 +49,7 @@ export class Bullet3 extends BulletBase {
            this.vector = this.vector.normalize().multiplyScalar(bulletSpeed);
         }
     }
+
     /**
      * 实时帧更新
      */
@@ -122,9 +122,8 @@ export class Bullet3 extends BulletBase {
                            e.subHP(attack,this.gunBase.data);
                         }
                     }else{
+                        e.raycastResults = targetResult;
                         e.subHP(attack,this.gunBase.data);
-                        //敌人流血特效
-                        this.enemyBlood(targetResult);
                     }
                 }else if(cls instanceof Sundries){
                     const sundrie: Sundries = cls as Sundries;

+ 1 - 1
profiles/v2/packages/reference-image.json

@@ -3,6 +3,6 @@
   "config": {
     "images": [],
     "sceneUUID": {},
-    "scene": "5863ff8c-cded-4bbf-9cdf-eaeb087c9ba0"
+    "scene": "10795865-5525-41fc-8bf7-0e8d6983b214"
   }
 }