Beispiel #1
0
        public void NpcEnable()
        {
            if (Params == null)
            {
                LocalConsole.Instance.Log($"Npc {this.name} has no associated AIParams object, instantiating default...", true);
                Params = Instantiate(AIParams.GetDefault());
            }

            if (NavAgent == null)
            {
                NavAgent = GetComponent <NavMeshAgent>();
                if (NavAgent == null)
                {
                    NavAgent = this.gameObject.AddComponent <NavMeshAgent>();
                }
            }

            InitNavAgent();

            if (Anim == null)
            {
                Anim = GetComponent <Animator>();
                if (Anim == null)
                {
                    Debug.Log($"{this.gameObject.name} doesn't have a doesn't have an Animator attached!");
                }
            }

            if (RigidBody == null)
            {
                Rigidbody rb = this.gameObject.AddComponent <Rigidbody>();
                rb.isKinematic = true;
                _rigidBody     = rb;
            }

            InitRigidBody();

            if (AreaScanCol == null)
            {
                Debug.LogError($"{this.gameObject.name} is missing its AreaScanCol, assign in editor! Attempting to recover...");

                GameObject child = Instantiate(new GameObject());
                child.transform.parent = this.transform.root;
                child.layer            = LayerMask.NameToLayer("Ignore Raycast");

                SphereCollider newCol = child.AddComponent <SphereCollider>();
                _areaScanCol = newCol;

                if (AreaScanCol == null)
                {
                    Debug.LogError($"{this.gameObject.name} AreaScanCol is still null after attempt!");
                }
            }

            InitAreaScanCol();

            ViewCone = new FOV((ViewConeOrigin != null ? ViewConeOrigin.position + this.transform.forward : this.transform.forward), _aiParams.FOV);

            EntType = EntityType.NPC;
        }
Beispiel #2
0
        ///--------------------------------------------------------------------
        /// AIParams methods
        ///--------------------------------------------------------------------

        public static AIParams GetDefault()
        {
            AIParams p = CreateInstance <AIParams>();

            p.SetType(NpcType.BASE);
            p.SetAwareMax(DEF_AWARE_MAX);
            p.SetAwareMed(DEF_AWARE_MED);
            p.SetAwareClose(DEF_AWARE_CLOSE);
            p.SetAtkDist(DEF_ATK_DIST);
            p.SetStopDist(DEF_STOP_DIST);
            p.SetChkIdle(DEF_CHK_IDLE);
            p.SetChkAlert(DEF_CHK_ALERT);
            p.SetMoveSpeed(DEF_MOVE_SPD);
            p.SetMoveWalk(DEF_MOVE_WALK);
            p.SetRoam(false);
            p.SetRoamDist(DEF_ROAM_DIST);
            p.SetRoamTime(DEF_ROAM_TIME);
            p.SetRoamPts(0);
            p.SetPatienceTime(DEF_PATIENCE_TIME);
            p.SetPredator(false);
            p.SetTerritorial(false);
            p.SetSquad(false);
            p.SetFlighty(false);
            p.SetRetarget(false);
            p.SetProxPct(DEF_PROX_PCT);
            p.SetRotSpd(DEF_ROT_SPD);
            p.SetRotAngle(DEF_ROT_ANGLE);
            p.SetAnimDelay(0.0f);
            p.SetAccelBase(DEF_ACCEL_BASE);
            p.SetAtkSlow(DEF_ATK_SLOW);
            p.SetAtkInit(0.0f);
            p.SetAtkEnd(0.0f);

            return(p);
        }