Browse Source

修复击飞速度过快的敌人击飞无效问题

LAPTOP-OM1V99U2\永远de小亡灵 11 tháng trước cách đây
mục cha
commit
ba782db216

+ 28 - 24
ActionTowerDefense/Assets/Scripts/Demonic.cs

@@ -549,40 +549,43 @@ public class Demonic : MoveCharacter
                 }
                 else
                 {
-                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
+                    if (weakTime <= -0.1)
                     {
-                        ani.Play("weak", 0, 0);
-                        aniCollider.Play("Weak", 0, 0);
-                        rb.velocity = Vector3.zero;
-                        weakTime = totalWeakTime;
-                    }
-
-                    rb.velocity = new Vector3(velocityAddition, rb.velocity.y,0);
-                }
-                if (weakTime <= 0)
-                {
-                    if (upFirstAfterWeaknessOrNot)
-                    {
-                        if (AdjustHeight())
+                        if (upFirstAfterWeaknessOrNot)
                         {
-                            ChangeState(CharacterState.Idle);
+                            if (AdjustHeight())
+                            {
+                                ChangeState(CharacterState.Idle);
+                            }
+                            else
+                            {
+                                if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "walk")
+                                {
+                                    ani.Play("walk", 0, 0);
+                                    aniCollider.Play("Walk", 0, 0);
+                                }
+                            }
                         }
                         else
                         {
-                            if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "walk")
-                            {
-                                ani.Play("walk", 0, 0);
-                                aniCollider.Play("Walk", 0, 0);
-                            }
+                            ChangeState(CharacterState.Idle);
                         }
+
+                        break;
                     }
-                    else
+                    else 
                     {
-                        ChangeState(CharacterState.Idle);
+                        if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
+                        {
+                            ani.Play("weak", 0, 0);
+                            aniCollider.Play("Weak", 0, 0);
+                            rb.velocity = Vector3.zero;
+                            weakTime = totalWeakTime;
+                        }
                     }
-
-                    break;
+                    rb.velocity = new Vector3(velocityAddition, rb.velocity.y,0);
                 }
+
                 break;
             case CharacterState.BaGua:
                 if (adsorbTime < 0.5)
@@ -793,6 +796,7 @@ public class Demonic : MoveCharacter
                 break;
             case CharacterState.Weak:
                 weakTime = totalWeakTime;
+                rb.AddForce(weakForce);
                 if (canFly)
                 {
                     rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;

+ 2 - 2
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -450,7 +450,6 @@ public class Enemy : MoveCharacter
                 }
                 break;
             case CharacterState.Weak:
-
                 if(rb.velocity.magnitude > 1)
                 {
                     if(ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
@@ -475,7 +474,7 @@ public class Enemy : MoveCharacter
                 }
                 else
                 {
-                    if (weakTime <= 0)
+                    if (weakTime <= -0.1)
                     {
                         if (upFirstAfterWeaknessOrNot)
                         {
@@ -813,6 +812,7 @@ public class Enemy : MoveCharacter
                         break;
                     default:
                         weakTime = totalWeakTime;
+                        rb.AddForce(weakForce);
                         if (canFly)
                         {
                             rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;

+ 11 - 2
ActionTowerDefense/Assets/Scripts/MoveCharacter.cs

@@ -35,6 +35,8 @@ public class MoveCharacter : Character
     public float weakTime;
     public float totalWeakTime;
     public float weakHitRate = 2;
+    [HideInInspector]
+    public Vector3 weakForce;
 
     [Header("Ò×É˼õÉË")]
     public float easyToGetHit = 0.2f;
@@ -383,7 +385,13 @@ public class MoveCharacter : Character
         {
             ChangeState(CharacterState.Die);
             if (!canNotAddForce)
-                rb.AddForce(force);
+            {
+                weakForce = force;
+            }
+            else
+            {
+                weakForce = Vector3.zero;
+            }
             return;
         }
         if (canNotChangeHurt)
@@ -400,9 +408,10 @@ public class MoveCharacter : Character
         {
             if (changeHurt && beRepelValue <= 0)
             {
-                ChangeState(CharacterState.Weak);
                 if (!canNotAddForce)
                     rb.AddForce(force);
+                ChangeState(CharacterState.Weak);
+                
             }
         }