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 }); }
protected override bool OnDone(GoapAgent agent, WithContext context) { base.OnDone(agent, context); targetPositions[agent].ReturnSelf(); SightSensor sight = agent.GetComponent <SightSensor>(); if (sight != null) { sight.LookAround(); } return(true); }
void Awake() { sight = GetComponent <SightSensor>(); }