Эх сурвалжийг харах

单位下落的时候加上惯性

LAPTOP-OM1V99U2\永远de小亡灵 1 жил өмнө
parent
commit
7df29fd139

+ 20 - 41
ActionTowerDefense/Assets/Scripts/Demonic.cs

@@ -439,48 +439,27 @@ public class Demonic : MoveCharacter
                     ChangeState(CharacterState.Idle);
                     break;
                 }
-                //if (foot.canStepPlayers.Count > 0)
-                //{
-                //    Jump(jumpSpeed / 2);
-                //    StepOther();
-                //    break;
-                //}
-                //if (foot.canStepEnemyList.Count > 0)
-                //{
-                //    Jump(jumpSpeed / 2);
-                //    StepEnemy();
-                //    break;
-                //}
-                //if (btnJumpPress || cacheJumpTime > 0)
-                //{
-                //    if (!airJumped)
-                //    {
-                //        airJumped = true;
-                //        AirJump();
-                //        break;
-                //    }
-                //    else if (canJumpTick >= runner.Tick)
-                //    {
-                //        Jump();
-                //        break;
-                //    }
-                //}
-                rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
+                Vector3 velocity = rb.velocity;
+                velocity.y += extraFallGravity * Time.deltaTime;
+                if (leftDir.x > 0.3f)
+                {
+                    velocity.x = moveSpeed;
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        Turn();
+                    }
+                }
+                else if (leftDir.x < -0.3f)
+                {
+                    velocity.x = -moveSpeed;
+                    if (bodyTrans.localScale.x < 0)
+                    {
+                        Turn();
+                    }
+                }
+
+                rb.velocity = velocity;
                 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:
                 pastComaTime += Time.deltaTime;
                 if (pastComaTime >= comaTime)

+ 20 - 11
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -309,12 +309,7 @@ public class Enemy : MoveCharacter
                 }
                 if (leftDir.x > 0.3f)
                 {
-                    //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
                     rb.velocity = Vector3.right * moveSpeed;
-                    //if (rb.velocity.x > maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
                     if (bodyTrans.localScale.x > 0)
                     {
                         Turn();
@@ -322,12 +317,7 @@ public class Enemy : MoveCharacter
                 }
                 else if (leftDir.x < -0.3f)
                 {
-                    //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
                     rb.velocity = Vector3.left * moveSpeed;
-                    //if (rb.velocity.x < -maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
                     if (bodyTrans.localScale.x < 0)
                     {
                         Turn();
@@ -408,7 +398,26 @@ public class Enemy : MoveCharacter
                     }
                     break;
                 }
-                rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
+                Vector3 velocity = rb.velocity;
+                velocity.y += extraFallGravity * Time.deltaTime;
+                if (leftDir.x > 0.3f)
+                {
+                    velocity.x = moveSpeed;
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        Turn();
+                    }
+                }
+                else if (leftDir.x < -0.3f)
+                {
+                    velocity.x = - moveSpeed;
+                    if (bodyTrans.localScale.x < 0)
+                    {
+                        Turn();
+                    }
+                }
+
+                rb.velocity = velocity;
                 break;
             case CharacterState.Attack:
                 if (attackTime <= 0)