Ver Fonte

角色跑斜线

WGL há 4 meses atrás
pai
commit
dc248d4e56

+ 8 - 15
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -273,7 +273,7 @@ public class Demonic : MoveCharacter
         pastAttackTime += Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
-
+        Vector3 velocity = rb.velocity;
         switch (state)
         {
             case CharacterState.Idle:
@@ -309,7 +309,9 @@ public class Demonic : MoveCharacter
                         ChangeState(CharacterState.Run);
                         break;
                     }
-                    rb.velocity = Vector3.right * velocityAddition;
+                    velocity.x = velocityAddition;
+                    rb.velocity = velocity;
+
                 }
                 break;
             case CharacterState.Run:
@@ -346,12 +348,8 @@ public class Demonic : MoveCharacter
                     }
                     if (leftDir.x > 0.3f)
                     {
-                        //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                        rb.velocity = Vector3.right * (moveSpeed + velocityAddition);
-                        //if (rb.velocity.x > maxMoveSpeed)
-                        //{
-                        //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                        //}
+                        velocity.x = moveSpeed + velocityAddition;
+                        rb.velocity = velocity;
                         if (bodyTrans.localScale.x > 0)
                         {
                             Turn();
@@ -359,12 +357,8 @@ public class Demonic : MoveCharacter
                     }
                     else if (leftDir.x < -0.3f)
                     {
-                        //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                        rb.velocity = Vector3.right * (-moveSpeed + velocityAddition);
-                        //if (rb.velocity.x < -maxMoveSpeed)
-                        //{
-                        //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                        //}
+                        velocity.x = -moveSpeed + velocityAddition;
+                        rb.velocity = velocity;
                         if (bodyTrans.localScale.x < 0)
                         {
                             Turn();
@@ -459,7 +453,6 @@ public class Demonic : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
-                Vector3 velocity = rb.velocity;
                 velocity.y += extraFallGravity * Time.deltaTime;
                 if (leftDir.x > 0.3f)
                 {

+ 5 - 4
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -214,7 +214,7 @@ public class Enemy : MoveCharacter
         pastAttackTime += Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
-
+        Vector3 velocity = rb.velocity;
         switch (state)
         {
             case CharacterState.Idle:
@@ -286,7 +286,8 @@ public class Enemy : MoveCharacter
                     }
                     if (leftDir.x > 0.3f)
                     {
-                        rb.velocity = Vector3.right * moveSpeed;
+                        velocity.x = moveSpeed;
+                        rb.velocity = velocity;
                         if (bodyTrans.localScale.x > 0)
                         {
                             Turn();
@@ -294,7 +295,8 @@ public class Enemy : MoveCharacter
                     }
                     else if (leftDir.x < -0.3f)
                     {
-                        rb.velocity = Vector3.left * moveSpeed;
+                        velocity.x = - moveSpeed;
+                        rb.velocity = velocity;
                         if (bodyTrans.localScale.x < 0)
                         {
                             Turn();
@@ -389,7 +391,6 @@ public class Enemy : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
-                Vector3 velocity = rb.velocity;
                 velocity.y += extraFallGravity * Time.deltaTime;
                 if (leftDir.x > 0.3f)
                 {

+ 6 - 3
ActionTowerDefense/Assets/Scripts/Characters/PlayerController.cs

@@ -878,6 +878,7 @@ public class PlayerController : MoveCharacter
                     }
                 }
             }
+            
         }
         return false;
     }
@@ -968,7 +969,8 @@ public class PlayerController : MoveCharacter
                 {
                     break;
                 }
-                rb.velocity = Vector3.right * velocityAddition;
+                velocity.x = velocityAddition;
+                rb.velocity = velocity;
 
                 break;
             case CharacterState.Run:
@@ -985,12 +987,13 @@ public class PlayerController : MoveCharacter
                 {
                     if (leftDir.x > 0.3f)
                     {
-                        rb.velocity = new Vector3(moveSpeed + velocityAddition, 0, 0);
+                        velocity.x = moveSpeed + velocityAddition;
                     }
                     else if (leftDir.x < -0.3f)
                     {
-                        rb.velocity = new Vector3(-moveSpeed + velocityAddition, 0, 0);
+                        velocity.x = -moveSpeed + velocityAddition;
                     }
+                    rb.velocity = velocity;
                 }
 
                 break;