Esempio n. 1
0
        public override List <IStateful> GetAllTargets(GoapAgent agent)
        {
            if (!targetPositions.ContainsKey(agent))
            {
                targetPositions[agent]   = null;
                previousPositions[agent] = agent.transform.position;
            }

            WanderPosition targetPosition = targetPositions[agent];

            if (targetPosition == null || !targetPosition.gameObject.activeInHierarchy)
            {
                targetPositions[agent]            = wanderPool.Borrow <WanderPosition>();
                targetPosition                    = targetPositions[agent];
                targetPosition.transform.position = GetRandomPosition(agent.transform.position,
                                                                      wanderingMaxDistance);
                previousPositions[agent] = agent.transform.position;
            }
            else if (Vector3.Distance(previousPositions[agent], agent.transform.position) > wanderingMaxDistance)
            {
                // Used in case the agent moved and is now away from the original wander position
                targetPositions[agent].transform.position = GetRandomPosition(agent.transform.position,
                                                                              wanderingMaxDistance);
            }

            return(new List <IStateful> {
                targetPosition
            });
        }
Esempio n. 2
0
        public override List <IStateful> GetAllTargets(GoapAgent agent)
        {
            if (!agentPositions.ContainsKey(agent))
            {
                agentPositions[agent] = wanderPool.Borrow <WanderPosition>();
            }

            WanderPosition wanderPos = agentPositions[agent];

            DangerSensor     dangerSensor = agent.GetComponent <DangerSensor>();
            SightSensor      sightSensor  = agent.GetComponent <SightSensor>();
            List <IStateful> threats      = dangerSensor.GetThreats();

            //Vector3 targetPosition = Vector3.zero;

            //foreach (IStateful threat in threats) {
            //    Component threatComp = threat as Component;
            //    targetPosition = targetPosition + (agent.transform.position - threatComp.transform.position);
            //}

            //targetPosition = (agent.transform.position + targetPosition) * runAwayDistance;
            //wanderPos.transform.position = sightSensor.GetRandomPosition(runAwayDistance, targetPosition);
            wanderPos.transform.position = sightSensor.GetRandomPosition(runAwayDistance, agent.transform.position);

            return(new List <IStateful> {
                wanderPos
            });
        }