Exemple #1
0
        protected override bool InRange(Stimulation stim)
        {
            float visibilityAmount = CalculateInRangeAmount(stim);


            //if(debugOn)
            //   Debug.Log(visibilityAmount);


            //if it is smart that normal
            if (owner.Intelligence > 0.5f)
            {
                float v = owner.Intelligence / 2.0f;
                visibilityAmount = Mathf.Min(visibilityAmount + (visibilityAmount * v), 1.0f);
            }
            //if it is dumb that normal
            else if (owner.Intelligence <= 0.5f)
            {
                float v = Mathf.Abs((owner.Intelligence - 0.5f) / 2.0f);
                visibilityAmount = Mathf.Max(visibilityAmount - (visibilityAmount * v), 0.0f);
            }


            return(visibilityAmount > MIN_ENTER_VALUE);
        }
 public AI_Interest(Stimulation stim, float inRangeAmount)
 {
     this.inRangeAmount = inRangeAmount;
     inRange            = false;
     stimulation        = stim;
     UpdatePosition();
 }
Exemple #3
0
        private void OnDamage(DamageInfo info, DamageablePart damageablePart)
        {
            Stimulation stim = null;

            if (info.sender != null)
            {
                stim = info.sender.GetComponentInChildren <Stimulation>();
            }

            if (owner != null && stim != null && (owner.CurrentInterest == null || owner.CurrentInterest.stimulation == null || owner.CurrentInterest.stimulation != stim))
            {
                AI_Interest interest = GetInterestIfExits(stim);

                if (interest != null)
                {
                    interest.lastKnowPosition = info.sender.transform.position;
                }

                else
                {
                    interest = new AI_Interest(stim, 0.35f);
                    interest.lastKnowPosition = info.sender.transform.position;
                    interest.inRange          = true;
                    interest.isAttackingMe    = true;

                    InterestList.Add(interest);
                }
            }
        }
        protected virtual void OnTriggerEnter(Collider other)
        {
            Stimulation stim = other.GetComponent <Stimulation>();

            if (stim != null)
            {
                InterestList.Add(new AI_Interest(stim, CalculateInRangeAmount(stim)));
            }
        }
Exemple #5
0
        //chekc if the collider is visible
        protected override float CalculateInRangeAmount(Stimulation stim)
        {
            Vector3 stimDirection = (stim.Collider.bounds.center - thisCollider.bounds.center).normalized;
            Vector3 thisForward   = transform.forward;

            float angle = Vector2.Angle(new Vector2(stimDirection.x, stimDirection.z), new Vector2(thisForward.x, thisForward.z));


            if (angle > visualAngle)
            {
                return(0.0f);
            }

            RaycastHit[] hitInfo = Physics.RaycastAll(new Ray(thisCollider.bounds.center, stimDirection), currentRange, visualLayer.value, QueryTriggerInteraction.Ignore);

            Collider closeCollider = null;
            float    minDistance   = float.MaxValue;


            for (int n = 0; n < hitInfo.Length; n++)
            {
                if (hitInfo[n].distance < minDistance)
                {
                    minDistance   = hitInfo[n].distance;
                    closeCollider = hitInfo[n].collider;
                }
            }


            //Debug.Log(closeCollider.name);
            if (closeCollider == null)
            {
                return(0.0f);
            }


            if (closeCollider == stim.Collider)
            {
                float visibilityAmount = 0.0f;
                visibilityAmount += Mathf.Abs(((Mathf.Min(Mathf.Abs(angle), visualAngle) / visualAngle) / 2.0f) - 0.5f);


                Vector3 targetPos = stim.Collider.bounds.center;
                Vector3 centerPos = thisCollider.bounds.center;

                float distance = Vector3.Distance(targetPos, centerPos);
                visibilityAmount += Mathf.Abs(((Mathf.Min(distance, range) / range) / 2.0f) - 0.5f);

                return(visibilityAmount);
            }


            return(0.0f);
        }
Exemple #6
0
        private AI_Interest GetInterestIfExits(Stimulation stim)
        {
            for (int n = 0; n < InterestList.Count; n++)
            {
                if (InterestList[n].stimulation == stim)
                {
                    return(InterestList[n]);
                }
            }

            return(null);
        }
Exemple #7
0
        private bool StimulationExitsInInterestList(Stimulation stim)
        {
            for (int n = 0; n < InterestList.Count; n++)
            {
                if (InterestList[n].stimulation == stim)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
        protected override bool CheckIfStillInRange(Stimulation stim)
        {
            float visibilityAmount = CalculateInRangeAmount(stim);

            if (visibilityAmount < MIN_EXIT_VALUE)
            {
                float blurryAmount = Mathf.Abs(visibilityAmount - 1.0f);


                return(Mathf.Abs((blurryAmount - owner.Intelligence)) > MIN_EXIT_VALUE);
            }


            return(true);
        }
 protected abstract bool CheckIfStillInRange(Stimulation stim);
 protected abstract bool InRange(Stimulation stim);
 protected abstract float CalculateInRangeAmount(Stimulation stim);