Browse Source

虚弱状态直接击飞

LAPTOP-OM1V99U2\永远de小亡灵 1 năm trước cách đây
mục cha
commit
7f39d36c3e

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

@@ -11,7 +11,7 @@ public enum CharacterState
     Run = 2,
     Rise = 3,//空中上升
     Fall = 4,//空中下落
-    Hurt = 5,
+    //Hurt = 5,
     Attack = 6,
     KeepAttack = 7,
     Summon = 8,
@@ -95,7 +95,7 @@ public class Character : MonoBehaviour
     public bool shootTrack = false;
     [HideInInspector]
     public float invincibleTime;
-    public float totalInvincibleTime = 2f;
+    //public float totalInvincibleTime = 2f;
     public Character targetCharacter;
     public List<Character> beTargetCharacter = new List<Character>(); //被哪些锁定
     public SearchTrigger searchTrigger;

+ 61 - 38
ActionTowerDefense/Assets/Scripts/Demonic.cs

@@ -259,7 +259,7 @@ public class Demonic : MoveCharacter
     public override void OnState()
     {
         base.OnState();
-        hurtKeepTime -= Time.deltaTime;
+        //hurtKeepTime -= Time.deltaTime;
         attackTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;
@@ -455,20 +455,20 @@ public class Demonic : MoveCharacter
                 //}
                 rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
                 break;
-            case CharacterState.Hurt:
-                if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (!foot.TrigGround)
-                {
-                    rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
-                }
-                Vector3 vel = rb.velocity;
-                vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
-                rb.velocity = vel;
-                break;
+            //case CharacterState.Hurt:
+            //    if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
+            //    {
+            //        ChangeState(CharacterState.Idle);
+            //        break;
+            //    }
+            //    if (!foot.TrigGround)
+            //    {
+            //        rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
+            //    }
+            //    Vector3 vel = rb.velocity;
+            //    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+            //    rb.velocity = vel;
+            //    break;
             case CharacterState.Coma:
                 if (!isCaughtByCook)
                 {
@@ -505,7 +505,42 @@ public class Demonic : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
-                rb.velocity = Vector3.right * velocityAddition;
+                if (rb.velocity.magnitude > 1)
+                {
+                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
+                    {
+                        ani.Play("hitted", 0, 0);
+                        aniCollider.Play("Hurt", 0, 0);
+                    }
+                    Vector3 vel = rb.velocity;
+                    if (!canFly)
+                    {
+                        if (foot.TrigGround && vel.y < 0)
+                        {
+                            vel.y = 0;
+                        }
+                        else
+                        {
+                            vel += Vector3.up * extraFallGravity * Time.deltaTime;
+                        }
+
+                    }
+
+                    vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
+                    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+                    rb.velocity = vel;
+                }
+                else
+                {
+                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
+                    {
+                        ani.Play("weak", 0, 0);
+                        aniCollider.Play("Weak", 0, 0);
+                        rb.velocity = Vector3.zero;
+                    }
+
+                    rb.velocity = new Vector3(velocityAddition, rb.velocity.y,0);
+                }
                 break;
             default:
                 break;
@@ -538,8 +573,8 @@ public class Demonic : MoveCharacter
             case CharacterState.Fall:
                 rb.velocity = Vector3.zero;
                 break;
-            case CharacterState.Hurt:
-                break;
+            //case CharacterState.Hurt:
+            //    break;
             case CharacterState.Coma:
                 canMove = true;
                 foreach(GameObject i in HitCols)
@@ -554,10 +589,7 @@ public class Demonic : MoveCharacter
                 isDie = false;
                 break;
             case CharacterState.Weak:
-                if (canFly)
-                {
-                    rb.constraints += 4; //RigidbodyConstraints.FreezePositionY = 4£¬²»ÄÜÖ±½Ó¼Ó
-                }
+                beRepelValue = totalBeRepelValue;
                 break;
             case CharacterState.Float:
                 canMove = true;
@@ -592,13 +624,13 @@ public class Demonic : MoveCharacter
                 aniCollider.Play("Fall", 0, 0);
                 //animalAni.SetInteger("state", (int)PlayerState.Fall);
                 break;
-            case CharacterState.Hurt:
-                ani.Play("hitted", 0, 0);
-                aniCollider.Play("Hurt", 0, 0);
-                invincibleTime = totalInvincibleTime;
-                hurtKeepTime = minHurtKeepTime;
-                //ani.Play("Invincible", 2, 0);
-                break;
+            //case CharacterState.Hurt:
+            //    ani.Play("hitted", 0, 0);
+            //    aniCollider.Play("Hurt", 0, 0);
+            //    invincibleTime = totalInvincibleTime;
+            //    hurtKeepTime = minHurtKeepTime;
+            //    //ani.Play("Invincible", 2, 0);
+            //    break;
             case CharacterState.Coma:
                 //ani.Play("Coma", 0, 0);
                 ani.Play("idle", 0, 0);
@@ -622,16 +654,7 @@ public class Demonic : MoveCharacter
                 dieKeepTime = totalDieKeepTime;
                 break;
             case CharacterState.Weak:
-                aniCollider.Play("Weak", 0, 0);
-                ani.Play("weak", 0, 0);
-                Vector3 velocity = rb.velocity;
-                velocity.y = weakUpSpeed;
-                rb.velocity = velocity;
                 weakTime = totalWeakTime;
-                if (canFly)
-                {
-                    rb.constraints -= RigidbodyConstraints.FreezePositionY;
-                }
                 break;
             case CharacterState.Float:
                 canMove = false;

+ 76 - 43
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -226,7 +226,7 @@ public class Enemy : MoveCharacter
     public override void OnState()
     {
         base.OnState();
-        hurtKeepTime -= Time.deltaTime;
+        //hurtKeepTime -= Time.deltaTime;
         attackTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;
@@ -429,20 +429,20 @@ public class Enemy : MoveCharacter
                 //}
                 rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
                 break;
-            case CharacterState.Hurt:
-                if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (!foot.TrigGround && !canFly)
-                {
-                    rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
-                }
-                Vector3 vel = rb.velocity;
-                vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
-                rb.velocity = vel;
-                break;
+            //case CharacterState.Hurt:
+            //    if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
+            //    {
+            //        ChangeState(CharacterState.Idle);
+            //        break;
+            //    }
+            //    if (!foot.TrigGround && !canFly)
+            //    {
+            //        rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
+            //    }
+            //    Vector3 vel = rb.velocity;
+            //    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+            //    rb.velocity = vel;
+            //    break;
             case CharacterState.Attack:
                 if (attackTime <= 0)
                 {
@@ -463,6 +463,43 @@ public class Enemy : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
+                if(rb.velocity.magnitude > 1)
+                {
+                    if(ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
+                    {
+                        ani.Play("hitted",0,0);
+                        aniCollider.Play("Hurt",0,0);
+                    }
+                    Vector3 vel = rb.velocity;
+                    if (!canFly)
+                    {
+                        if (foot.TrigGround && vel.y < 0)
+                        {
+                            vel.y = 0;
+                        }
+                        else
+                        {
+                            vel += Vector3.up * extraFallGravity * Time.deltaTime;
+                        }
+                        
+                    }
+
+                    vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
+                    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+                    rb.velocity = vel;
+                }
+                else
+                {
+                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
+                    {
+                        ani.Play("weak",0,0);
+                        aniCollider.Play("Weak",0,0);
+                        rb.velocity = Vector3.zero;
+                    }
+
+                }
+
+
                 break;
             case CharacterState.Coma:
                 if (!isCaughtByCook)
@@ -633,8 +670,8 @@ public class Enemy : MoveCharacter
             case CharacterState.Fall:
                 rb.velocity = Vector3.zero;
                 break;
-            case CharacterState.Hurt:
-                break;
+            //case CharacterState.Hurt:
+            //    break;
             case CharacterState.Attack:
                 aniCollider.Play("NotAttack", 1, 0);
                 break;
@@ -642,7 +679,7 @@ public class Enemy : MoveCharacter
                 isDie = false;
                 break;
             case CharacterState.Weak:
-
+                beRepelValue = totalBeRepelValue;
                 break;
             case CharacterState.Float:
                 canMove = true;
@@ -724,25 +761,25 @@ public class Enemy : MoveCharacter
                 aniCollider.Play("Fall", 0, 0);
                 //animalAni.SetInteger("state", (int)PlayerState.Fall);
                 break;
-            case CharacterState.Hurt:
-                switch (oldState)
-                {
-                    case CharacterState.ReadyToRush:
-                    case CharacterState.RushAttack:
-                    case CharacterState.ReadyToDownRush:
-                    case CharacterState.DownRush:
-                    case CharacterState.Rush:
-                        state = oldState;
-                        beRepelValue = totalBeRepelValue;
-                        break;
-                    default:
-                        ani.Play("hitted", 0, 0);
-                        aniCollider.Play("Hurt", 0, 0);
-                        invincibleTime = totalInvincibleTime;
-                        hurtKeepTime = minHurtKeepTime;
-                        break;
-                }
-                break;
+            //case CharacterState.Hurt:
+            //    switch (oldState)
+            //    {
+            //        case CharacterState.ReadyToRush:
+            //        case CharacterState.RushAttack:
+            //        case CharacterState.ReadyToDownRush:
+            //        case CharacterState.DownRush:
+            //        case CharacterState.Rush:
+            //            state = oldState;
+            //            beRepelValue = totalBeRepelValue;
+            //            break;
+            //        default:
+            //            ani.Play("hitted", 0, 0);
+            //            aniCollider.Play("Hurt", 0, 0);
+            //            invincibleTime = totalInvincibleTime;
+            //            hurtKeepTime = minHurtKeepTime;
+            //            break;
+            //    }
+            //    break;
             case CharacterState.Float:
                 canMove = false;
                 break;
@@ -781,19 +818,15 @@ public class Enemy : MoveCharacter
                     case CharacterState.RushAttack:
                     case CharacterState.ReadyToDownRush:
                     case CharacterState.DownRush:
+                    case CharacterState.Rush:
                         state = oldState;
                         beRepelValue = totalBeRepelValue;
                         break;
                     default:
-                        aniCollider.Play("Weak", 0, 0);
-                        ani.Play("weak", 0, 0);
-                        Vector3 velocity = rb.velocity;
-                        velocity.y = weakUpSpeed;
-                        rb.velocity = velocity;
                         weakTime = totalWeakTime;
+                        //hurtKeepTime = minHurtKeepTime;
                         break;
                 }
-
                 break;
             case CharacterState.FindPlayer:
                 isFindPlayer = false;

+ 16 - 14
ActionTowerDefense/Assets/Scripts/MoveCharacter.cs

@@ -18,12 +18,13 @@ public class MoveCharacter : Character
     [HideInInspector]
     public float weakTime;
     public float totalWeakTime;
-    public float weakUpSpeed = 10f;
+    //public float weakUpSpeed = 10f;
     public float decelerationRatio = 1f;
-    public float minHurtKeepTime = 0.2f;
-    [HideInInspector]
-    public float hurtKeepTime = 0;
-    public float hurtChangeVelocity = 1;
+    //public float minHurtKeepTime = 0.2f;
+    //[HideInInspector]
+    //public float hurtKeepTime = 0;
+    //public float hurtChangeVelocity = 1;
+    public float weakHitRate = 2;
 
     [Header("ÐÂÔöÑ£ÔβÎÊý")]
     public float comaTime = 5;
@@ -400,20 +401,21 @@ public class MoveCharacter : Character
             {
                 return;
             }
+            beRepelValue -= repelValue;
             if (changeHurt && state == CharacterState.Weak)
             {
-                ChangeState(CharacterState.Hurt);
-                rb.AddForce(force);
-                beRepelValue = totalBeRepelValue;
-                return;
+                rb.AddForce(force * weakHitRate);
             }
-            beRepelValue -= repelValue;
-            if (changeHurt && beRepelValue <= 0)
+            else
             {
-                ChangeState(CharacterState.Weak);
-                
+                if (changeHurt && beRepelValue <= 0)
+                {
+                    ChangeState(CharacterState.Weak);
+                    rb.AddForce(force);
+                }
             }
 
+
         }
         else
         {
@@ -421,7 +423,7 @@ public class MoveCharacter : Character
             {
                 pc = GetComponentInParent<PlayerController>();
             }
-            pc.BeHit(damage, force, changeHurt, repelValue);
+            pc.BeHit(damage, force, false, repelValue);
         }
     }
 

+ 71 - 38
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -846,7 +846,7 @@ public class PlayerController : MoveCharacter
     {
         base.OnState();
 
-        hurtKeepTime -= Time.deltaTime;
+        //hurtKeepTime -= Time.deltaTime;
         cacheJumpTime -= Time.deltaTime;
         cacheAttackTime -= Time.deltaTime;
         cacheSummonTime -= Time.deltaTime;
@@ -989,31 +989,31 @@ public class PlayerController : MoveCharacter
                 CachedPlayerInput();
                 rb.velocity = AirMove(rb.velocity);
                 break;
-            case CharacterState.Hurt:
-                if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
-                {
-                    if (CheckPlayerChangeState())
-                    {
-                        break;
-                    }
-                }
-                Vector3 vel = rb.velocity;
-                if (!foot.TrigGround)
-                {
-                    if (canfly)
-                    {
-                        vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
-                    }
-                    else
-                    {
-                        vel += Vector3.up * extraFallGravity * Time.deltaTime;
-                    }
+            //case CharacterState.Hurt:
+            //    if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
+            //    {
+            //        if (CheckPlayerChangeState())
+            //        {
+            //            break;
+            //        }
+            //    }
+            //    Vector3 vel = rb.velocity;
+            //    if (!foot.TrigGround)
+            //    {
+            //        if (canfly)
+            //        {
+            //            vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
+            //        }
+            //        else
+            //        {
+            //            vel += Vector3.up * extraFallGravity * Time.deltaTime;
+            //        }
                     
-                }
-                vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
-                rb.velocity = vel;
-                CachedPlayerInput();
-                break;
+            //    }
+            //    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+            //    rb.velocity = vel;
+            //    CachedPlayerInput();
+            //    break;
             case CharacterState.Coma:
                 break;
             case CharacterState.Attack:
@@ -1287,7 +1287,41 @@ public class PlayerController : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
-                rb.velocity = Vector3.right * velocityAddition;
+                if (rb.velocity.magnitude > 1)
+                {
+                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
+                    {
+                        ani.Play("hitted", 0, 0);
+                        aniCollider.Play("Hurt", 0, 0);
+                    }
+                    Vector3 vel = rb.velocity;
+                    if (!canfly)
+                    {
+                        if (foot.TrigGround && vel.y < 0)
+                        {
+                            vel.y = 0;
+                        }
+                        else
+                        {
+                            vel += Vector3.up * extraFallGravity * Time.deltaTime;
+                        }
+
+                    }
+
+                    vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
+                    vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
+                    rb.velocity = vel;
+                }
+                else
+                {
+                    if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
+                    {
+                        ani.Play("weak", 0, 0);
+                        aniCollider.Play("Weak", 0, 0);
+                        rb.velocity = Vector3.zero;
+                    }
+                    rb.velocity = new Vector3(velocityAddition, rb.velocity.y, 0);
+                }
                 break;
             case CharacterState.PullRope:
 
@@ -1454,8 +1488,8 @@ public class PlayerController : MoveCharacter
                 break;
             case CharacterState.Fall:
                 break;
-            case CharacterState.Hurt:
-                break;
+            //case CharacterState.Hurt:
+            //    break;
             case CharacterState.Coma:
                 canMove = true;
                 foreach (GameObject i in HitCols)
@@ -1489,6 +1523,7 @@ public class PlayerController : MoveCharacter
                 isDie = false;
                 break;
             case CharacterState.Weak:
+                beRepelValue = totalBeRepelValue;
                 break;
             default:
                 break;
@@ -1524,13 +1559,13 @@ public class PlayerController : MoveCharacter
                 ani.Play("fall", 0, 0);
                 //animalAni.SetInteger("state", (int)PlayerState.Fall);
                 break;
-            case CharacterState.Hurt:
-                aniCollider.Play("Hurt", 0, 0);
-                ani.Play("hitted", 0, 0);
-                invincibleTime = totalInvincibleTime;
-                hurtKeepTime = minHurtKeepTime;
-                //ani.Play("Invincible", 2, 0);
-                break;
+            //case CharacterState.Hurt:
+            //    aniCollider.Play("Hurt", 0, 0);
+            //    ani.Play("hitted", 0, 0);
+            //    invincibleTime = totalInvincibleTime;
+            //    hurtKeepTime = minHurtKeepTime;
+            //    //ani.Play("Invincible", 2, 0);
+            //    break;
             case CharacterState.Coma:
                 //ani.Play("Coma", 0, 0);
                 ani.Play("idle", 0, 0);
@@ -1611,10 +1646,8 @@ public class PlayerController : MoveCharacter
                 }
                 break;
             case CharacterState.Weak:
-                aniCollider.Play("Weak", 0, 0);
-                ani.Play("weak", 0, 0);
-                velocity.y = weakUpSpeed;
                 weakTime = totalWeakTime;
+                //hurtKeepTime = minHurtKeepTime;
                 break;
             default:
                 break;

+ 2 - 25
ActionTowerDefense/Assets/Scripts/Spirits/SoulBoom.cs

@@ -51,32 +51,9 @@ public class SoulBoom : MonoBehaviour
                         Vector3 pos2 = transform.position;
                         target = (pos1 - pos2).normalized;
 
-                        if((characters[i].isTran && characters[i].pc.hp- attackInfo.damage < 0 )
-                            ||characters[i].hp - attackInfo.damage < 0)
-                        {
-                            //characters[i].isSoulUnstable = false;
-                            characters[i].BeHit
-                                (attackInfo.damage, Vector3.zero,
-                                attackInfo.changeHurt, attackInfo.repelValue);
-                        }
-                        else
-                        {
-                            //characters[i].isSoulUnstable = false;
-                            characters[i].BeHit
-                                (attackInfo.damage, Vector3.zero,
-                                attackInfo.changeHurt, attackInfo.repelValue);
 
-                            characters[i].ChangeState(CharacterState.Hurt);
-                            characters[i].rb.AddForce(target * attackInfo.force);
-
-                            //if (isTransfiguration)
-                            //{
-                            //    characters[i].isSoulUnstable = true;
-                            //    characters[i].soulUnstableTime = soulUnstableTime;
-                            //    characters[i].ChangeMat(2);
-                            //}
-
-                        }
+                        characters[i].BeHit
+                            (attackInfo.damage, target * attackInfo.force, true, attackInfo.repelValue);