示例#1
0
        public override void OnModeEnter(Mode mode)
        {
            MAnimal animal = mode.Animal;

            IAlign SelfAligner  = animal.GetComponent <IAlign>();
            IAlign EnemyAligner = null;

            var pos = SelfAligner != null ? SelfAligner.MainPoint.position : animal.transform.position;

            var AllColliders = Physics.OverlapSphere(pos, FindRadius, animal.HitLayer);

            Collider MinDistanceCol;
            float    Distance = float.MaxValue;

            foreach (var col in AllColliders)
            {
                if (col.GetComponentInParent <MAnimal>() == animal)
                {
                    continue;                                                //Don't Find your own colliders
                }
                var DistCol = Vector3.Distance(animal.transform.position, col.transform.position);

                if (Distance > DistCol)
                {
                    Distance       = DistCol;
                    MinDistanceCol = col;
                    EnemyAligner   = col.GetComponentInParent <IAlign>();
                }
            }

            if (EnemyAligner != null)
            {
                EnemyAligner.Align(animal.transform);
            }
        }
示例#2
0
        public override void OnModeEnter(Mode mode)
        {
            MAnimal animal = mode.Animal;

            Vector3 HitDirection = animal.GetComponent <IMDamage>().HitDirection;

            if (HitDirection == Vector3.zero)
            {
                return;                                                           //Set it to random if there's no hit direction
            }
            HitDirection = Vector3.ProjectOnPlane(HitDirection, animal.UpVector); //Remove the Y on the Direction
            float angle = Vector3.Angle(animal.Forward, HitDirection);            //Get The angle
            bool  left  = Vector3.Dot(animal.Right, HitDirection) < 0;            //Calculate which directions comes the hit Left or right

            int Side = -99;

            switch (hitDirection)
            {
            case MDirectionalDamage.HitDirection.TwoSides:
                mode.AbilityIndex = left ? Left : Right;
                break;

            case MDirectionalDamage.HitDirection.FourSides:

                if (angle <= 45)
                {
                    Side = Front;
                }
                else if (angle >= 45 && angle <= 135)
                {
                    Side = left ? Right : Left;
                }
                else if (angle >= 135)
                {
                    Side = Back;
                }


                if (debug)
                {
                    var   Colordeb = Color.blue;
                    float mult     = 4;
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 45, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -45, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 135, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -135, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, angle * (left ? -1 : 1), 0) * animal.transform.forward * mult, Color.red, 3f);
                }


                break;

            case MDirectionalDamage.HitDirection.SixSides:

                if (debug)
                {
                    var   Colordeb = Color.blue;
                    float mult     = 4;
                    Debug.DrawRay(animal.transform.position, animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, -animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 60, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -60, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, 120, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, -120, 0) * animal.transform.forward * mult, Colordeb, 3f);
                    Debug.DrawRay(animal.transform.position, Quaternion.Euler(0, angle * (left ? -1 : 1), 0) * animal.transform.forward * mult, Color.red, 3f);
                }

                if (!left)
                {
                    if (angle >= 0 && angle <= 60)
                    {
                        Side = FrontRight;
                    }
                    else if (angle > 60 && angle <= 120)
                    {
                        Side = Right;
                    }
                    else if (angle > 120 && angle <= 180)
                    {
                        Side = BackRight;
                    }
                }
                else
                {
                    if (angle >= 0 && angle <= 60)
                    {
                        Side = FrontLeft;
                    }
                    else if (angle > 60 && angle <= 120)
                    {
                        Side = Left;
                    }
                    else if (angle > 120 && angle <= 180)
                    {
                        Side = BackLeft;
                    }
                }
                break;

            default:
                break;
            }
            mode.AbilityIndex = Side;
        }