Sfoglia il codice sorgente

远程单位射击角度

SZAND\msx_2 6 mesi fa
parent
commit
fdc6f82451

+ 13 - 0
ActionTowerDefense/Assets/Resources/Prefab/MySoldier/Demonic_Arrow.prefab

@@ -131,7 +131,9 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 38dc6c579f75e924697fbe3639d11c9f, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  freezeFrame: 0
   isFreeze: 0
+  hitStunTime: 0
 --- !u!1 &1637528673901708253
 GameObject:
   m_ObjectHideFlags: 0
@@ -1157,6 +1159,7 @@ MonoBehaviour:
   cookEffect: {fileID: 0}
   Attack_summonShootCanTransmit: 0
   debugAttackFrom: 0
+  hitResistance: 0
   matState: 1
   spinee: {fileID: 0}
   mesh: {fileID: 0}
@@ -1281,6 +1284,7 @@ MonoBehaviour:
   nextEndKeyTime: 0
   curKeyNum: 0
   attackType: 1
+  attackValue: 0
   curDamage: 0
   canHitFly: 1
   armorPiercing: 100
@@ -1334,6 +1338,7 @@ MonoBehaviour:
     attackName: "\u8D77\u624B\u4E09\u8FDE\u53D1"
     attackType: 1
     attackEffect: {fileID: 0}
+    attackValue: 0
     attackInfo:
       damage: 80
       attackDir: {x: -1, y: 0, z: 0}
@@ -1376,6 +1381,8 @@ MonoBehaviour:
     - {fileID: 8482269351142858204}
     - {fileID: 776105162125788029}
     - {fileID: 6220414675483084992}
+    maxUpAngle: 30
+    maxDownAngle: 30
     shootTrack: 1
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}
@@ -1384,6 +1391,7 @@ MonoBehaviour:
     attackName: "\u5C04\u7BAD"
     attackType: 1
     attackEffect: {fileID: 0}
+    attackValue: 0
     attackInfo:
       damage: 30
       attackDir: {x: -1, y: 0, z: 0}
@@ -1424,6 +1432,8 @@ MonoBehaviour:
     bulletPrefab: {fileID: 7473170563405908938, guid: 0460e8750cef0df4292f6d2bb56a4843, type: 3}
     shootPos:
     - {fileID: 8482269351142858204}
+    maxUpAngle: 30
+    maxDownAngle: 30
     shootTrack: 1
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}
@@ -1433,6 +1443,7 @@ MonoBehaviour:
     attackName: 
     attackType: 0
     attackEffect: {fileID: 0}
+    attackValue: 0
     attackInfo:
       damage: 0
       attackDir: {x: 0, y: 0, z: 0}
@@ -1472,6 +1483,8 @@ MonoBehaviour:
     armorPiercing: 0
     bulletPrefab: {fileID: 0}
     shootPos: []
+    maxUpAngle: 0
+    maxDownAngle: 0
     shootTrack: 0
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}

+ 5 - 0
ActionTowerDefense/Assets/Scripts/Characters/AttackController.cs

@@ -139,6 +139,7 @@ public class AttackInfo
         ai.sustainedInjury = sustainedInjury;
     }
 }
+
 public class AttackController : MonoBehaviour
 {
     //攻击类型
@@ -205,6 +206,10 @@ public class AttackController : MonoBehaviour
         public GameObject bulletPrefab;         //子弹
         [ShowIf("attackType", AttackType.Shoot)]
         public List<Transform> shootPos;        //子弹发射位置
+        [ShowIf("attackType", AttackType.Shoot)][LabelText("水平向上最大夹角")]
+        public float maxUpAngle;
+        [ShowIf("attackType", AttackType.Shoot)][LabelText("水平向下最大夹角")]
+        public float maxDownAngle;
         [ShowIf("attackType", AttackType.Shoot)]
         public bool shootTrack;                 //是否初始时瞄准目标
         [ShowIf("attackType", AttackType.Shoot)]

+ 1 - 0
ActionTowerDefense/Assets/Scripts/Characters/AttackTrigger.cs

@@ -99,6 +99,7 @@ public class AttackTrigger : MonoBehaviour
             }
         }
     }
+
     private void OnDisable()
     {
 

+ 12 - 0
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -130,6 +130,18 @@ public class Demonic : MoveCharacter
             case SearchState.InAttackScope:
                 if (targetCharacter != null)
                 {
+                    //ÅжÏÊÇ·ñÔÚÉä³Ì¼Ð½ÇÄÚ
+                    AttackController.AttackMethod am = attackController.curAttackMethod;
+                    if (am.attackType == AttackController.AttackType.Shoot && am.id != 0)
+                    {
+                        Vector3 dir = targetCharacter.beSearchTrigger.transform.position - transform.position;
+                        float angle = Vector3.Angle(dir, Vector3.left * bodyTrans.localScale.x);
+                        if ((dir.y > 0 && angle > am.maxUpAngle) || (dir.y < 0 && angle > am.maxDownAngle))
+                        {
+                            ChangeSearchState(SearchState.NoTarget);
+                            break;
+                        }
+                    }
                     attackDis = attackController.attackDistance + targetCharacter.beHitDistance;
                     if (!targetCharacter.gameObject.activeInHierarchy || targetCharacter.isDie
                         || Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) > attackDis)

+ 12 - 14
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -362,20 +362,7 @@ public class Enemy : MoveCharacter
                 rb.velocity = velocity;
                 break;
             case CharacterState.Attack:
-                attackController.attackTime -= Time.deltaTime;
-                attackController.attackKeyCount += Time.deltaTime;
-                if (!attackController.isAttackTriggerOn && attackController.attackKeyCount >=
-                    attackController.nextStartKeyTime && attackController.attackKeyCount <= attackController.nextEndKeyTime)
-                {
-                    attackController.isAttackTriggerOn = true;
-                    attackController.attackTrigger.gameObject.SetActive(true);             
-                }
-                else if (attackController.isAttackTriggerOn && attackController.attackKeyCount >= attackController.nextEndKeyTime)
-                {
-                    attackController.isAttackTriggerOn = false;
-                    attackController.attackTrigger.gameObject.SetActive(false);
-                    attackController.SetNextKeyTimes();
-                }
+                attackController.JudgeTriggerOnOff();
                 if (attackController.attackTime <= 0)
                 {
                     ChangeState(CharacterState.Idle);
@@ -616,6 +603,17 @@ public class Enemy : MoveCharacter
             case SearchState.InAttackScope:
                 if (targetCharacter != null)
                 {
+                    //ÅжÏÊÇ·ñÔÚÉä³Ì¼Ð½ÇÄÚ
+                    AttackController.AttackMethod am = attackController.curAttackMethod;
+                    if (am.attackType==AttackController.AttackType.Shoot && am.id != 0)
+                    {
+                        Vector3 dir = targetCharacter.beSearchTrigger.transform.position - transform.position;
+                        float angle = Vector3.Angle(dir, Vector3.left * bodyTrans.localScale.x);
+                        if ((dir.y > 0 && angle > am.maxUpAngle) || (dir.y < 0 && angle > am.maxDownAngle))
+                        {
+                            ChangeSearchState(SearchState.NoTarget);
+                        }
+                    }
                     attackDis = attackController.attackDistance + targetCharacter.beHitDistance;
                     if (!targetCharacter.gameObject.activeInHierarchy || targetCharacter.isDie
                         || Mathf.Abs(targetCharacter.transform.position.x - transform.position.x) > attackDis)

+ 14 - 0
ActionTowerDefense/Assets/Scripts/Characters/SearchTrigger.cs

@@ -203,6 +203,20 @@ public class SearchTrigger : MonoBehaviour
         for (int i = 0; i < list.Count; i++)
         {
             Character character = list[i];
+            //判断对象是否在远程单位的射击夹角范围内
+            AttackController.AttackMethod am = owner.attackController.curAttackMethod;
+            if (am.attackType == AttackController.AttackType.Shoot)
+            {
+                float up = am.maxUpAngle;
+                float down = am.maxDownAngle;
+                Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
+                float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
+                if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
+                {
+                    continue;
+                }
+            }
+            //判断是否在攻击范围内
             float distance = Mathf.Abs(character.transform.position.x - owner.transform.position.x);
             if (minDisChar == null || minDistance == -1 || minDistance > distance)
             {