Browse Source

修复索敌和落地冲突问题

LAPTOP-OM1V99U2\永远de小亡灵 11 months ago
parent
commit
925074cafe
1 changed files with 20 additions and 16 deletions
  1. 20 16
      ActionTowerDefense/Assets/Scripts/Enemy.cs

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

@@ -432,22 +432,22 @@ public class Enemy : MoveCharacter
                 }
                 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();
-                    }
-                }
+                //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;
@@ -709,6 +709,8 @@ public class Enemy : MoveCharacter
                 break;
             case CharacterState.Fall:
                 rb.velocity = Vector3.zero;
+                rb.useGravity = false;
+                rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ|RigidbodyConstraints.FreezePositionY;
                 break;
             //case CharacterState.Hurt:
             //    break;
@@ -816,6 +818,8 @@ public class Enemy : MoveCharacter
                 break;
             case CharacterState.Fall:
                 aniCollider.Play("Fall", 0, 0);
+                rb.useGravity = true;
+                rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ;
                 break;
             case CharacterState.Float:
                 canMove = false;