protected override void Awake()
 {
     myAgent = GetComponent <GoapAgent>();
     myAgent.WorldStateChecks.Add(CheckWorldState);
     MyAI = GetComponent <GoapAI>();
     RequiredStates.Add(new GoapState("In Weapon Range", true));
     SatisfiesStates.Add(new GoapState("Looking At Player", true));
 }
示例#2
0
    public CombatGoal(GoapAgent agent) : base(agent)
    {
        GoalName = "Combat Goal";

        RequiredWorldState.Add(new GoapState("Player Detected", true));
        RequiredWorldState.Add(new GoapState("Shoot At Player", true));

        myAI = agent.GetComponent <GoapAI>();
    }
示例#3
0
    public void spawnAI()
    {
        if (!GameManager.GM.RoundBegin)
        {
            if (UseNetwork)
            {
                NeuralNetController myNet   = NeuralNetController.NNC;
                int        NetworkAiToSpawn = Mathf.RoundToInt(Mathf.Lerp(MinAIToSpawn, MaxAIToSpawn, myNet.Outputs[(int)NetworkOutputNames.NumAi]));
                int        DetectionRadius  = Mathf.RoundToInt(Mathf.Lerp(MinDetectionRadius, MaxDetectionRadius, myNet.Outputs[(int)NetworkOutputNames.DetectionRadius]));
                bool       CanAim           = myNet.Outputs[(int)NetworkOutputNames.CanAim] > 0.5f;
                float      Accuracy         = Mathf.Lerp(MinAccuracy, MaxAccuracy, myNet.Outputs[(int)NetworkOutputNames.Accuracy]);
                int        numGoals         = Mathf.RoundToInt(Mathf.Lerp(1, 4, myNet.Outputs[(int)NetworkOutputNames.Goals]));
                BaseWeapon WeaponForAI      = Weapons[Mathf.RoundToInt(Mathf.Lerp(0, Weapons.Count - 1, myNet.Outputs[(int)NetworkOutputNames.Weapon]))];
                float      MaxHealth        = Mathf.Lerp(50, 200, myNet.Outputs[(int)NetworkOutputNames.MaxHealth]);

                for (int i = 0; i < NetworkAiToSpawn; ++i)
                {
                    // Get Position within Next Area.
                    GameObject nAI       = Instantiate(AIPrefab, GetRandomPosition(), Quaternion.identity, transform);
                    GoapAgent  tempAgent = nAI.GetComponent <GoapAgent>();
                    AddGoals(ref tempAgent, numGoals);

                    GoapAI myAIComp = nAI.GetComponent <GoapAI>();
                    myAIComp.DetectionRadius = DetectionRadius;
                    myAIComp.CanAimWeapon    = CanAim;
                    myAIComp.LookAccuracy    = Accuracy;
                    myAIComp.AddWeapon(WeaponForAI);
                    myAIComp.myDetectionObj.GetComponent <SphereCollider>().radius = DetectionRadius;

                    Health AIHealth = nAI.GetComponent <Health>();
                    AIHealth.MaxHealth = MaxHealth;

                    SpawnedAI.Add(myAIComp);
                    tempAgent.Initialise();
                    myAIComp.Initialise();
                }

                GameManager.GM.AIRemaining = NetworkAiToSpawn;
                GameManager.GM.RoundBegin  = true;
                GameManager.GM.UpdateAICount();
            }
        }
    }