瀏覽代碼

空中跳跃增加速度限制,原有多段跳逻辑优化

wulifu 1 年之前
父節點
當前提交
9b85fcd0b2
共有 1 個文件被更改,包括 7 次插入26 次删除
  1. 7 26
      ActionTowerDefense/Assets/Scripts/PlayerController.cs

+ 7 - 26
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -51,6 +51,7 @@ public class PlayerController : MoveCharacter
 
     public float jumpSpeed = 10;
     public float airJumpSpeed = 10;
+    public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
     //public float moveAcc = 5f;
     //public float airMoveAcc = 3f;
     public float rushSpeed = 100;
@@ -92,7 +93,7 @@ public class PlayerController : MoveCharacter
     public float totalCacheRushTime = 0.1f;
 
     public int airJumped;
-    public int jumpNumber = 2;  //最大跳跃次数
+    public int airJumpNumber = 1;  //最大跳跃次数
     public PlayerAttackState attackState;
     public float attackMoveSpeed = 5f;
     public Vector3 rushDir;
@@ -925,15 +926,9 @@ public class PlayerController : MoveCharacter
                 }
                 if (btnJumpPress || cacheJumpTime > 0)
                 {
-                    if (airJumped == 0 && jumpNumber >= 2 && rb.velocity.y < airJumpSpeed)
+                    if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
                     {
-                        airJumped = 1;
-                        AirJump();
-                        break;
-                    }
-                    if (airJumped == 1 && jumpNumber >= 3 && rb.velocity.y < airJumpSpeed)
-                    {
-                        airJumped = 2;
+                        airJumped++;
                         AirJump();
                         break;
                     }
@@ -980,24 +975,10 @@ public class PlayerController : MoveCharacter
                     }
                     else
                     {
-                        switch (airJumped)
+                        if (airJumped < airJumpNumber)
                         {
-                            case 0:
-                                if(jumpNumber >= 2)
-                                {
-                                    airJumped = 1;
-                                    AirJump();
-                                    
-                                }
-                                break;
-                            case 1:
-                                if(jumpNumber >= 3)
-                                {
-                                    airJumped = 2;
-                                    AirJump();
-                                }
-
-                                break;
+                            airJumped++;
+                            AirJump();
                         }
                     }
                     isClickBtnJump = false;