// Use this for initialization void Start() { float RandomPersonality = Random.value; Debug.Log(gameObject.name + ": " + RandomPersonality); if (RandomPersonality < 0.2f) { Personality = HenPersonalities.AGGRESSIVE; } if (RandomPersonality >= 0.2f && RandomPersonality < 0.5f) { Personality = HenPersonalities.COWARD; } if (RandomPersonality >= 0.5f && RandomPersonality < 0.9f) { Personality = HenPersonalities.PROTECTIVE; } if (RandomPersonality >= 0.9f) { Personality = HenPersonalities.UNLIKABLE; } CurrentStatus = HenStatus.ROAMING; agent = GetComponent <NavMeshAgent>(); }
private object Roam(object o) { CurrentStatus = HenStatus.ROAMING; movAgent.speed = 2.5f; GetComponent <RoamingBehaviour>().ExecuteBehaviour(Rooster); return(null); }
private object ChaseRooster(object o) { CurrentStatus = HenStatus.CATCHINGUP; movAgent.SetDestination(Rooster.transform.position); movAgent.speed = 5f; return(null); }
//---------------------------------------------------------------- DT Actions ---------------------------------------------------------------------- private object Wait(object o) { CurrentStatus = HenStatus.ENGAGING; movAgent.SetDestination(transform.position); AnimationTimer += Time.deltaTime; return(null); }
private object EngageChick(object o) { AnimationTimer = 0; CurrentStatus = HenStatus.ENGAGING; NearestChick.GetComponent <Rigidbody>().AddForce(transform.forward * PushForce, ForceMode.Impulse); NearestChick.GetComponent <Rigidbody>().AddForce(transform.up * PushForce, ForceMode.Impulse); transform.LookAt(NearestChick.transform); return(null); }
private object Flee(object o) { CurrentStatus = HenStatus.FLEEING; Vector3 EscapeDirection = transform.position - NearestPlayer.transform.position; movAgent.SetDestination(transform.position + (EscapeDirection.normalized) / 2f); movAgent.speed = 3.5f; return(null); }
private object ChasePlayer(object o) { CurrentStatus = HenStatus.GOINGTO; movAgent.speed = 3.5f; if (Vector3.Distance(transform.position, NearestPlayer.transform.position) > 0.5f) { movAgent.SetDestination(NearestPlayer.transform.position); } else { transform.LookAt(NearestPlayer.transform.position); } return(null); }
// Use this for initialization void Start() { float RandomPersonality = Random.value; Debug.Log(gameObject.name + ": " + RandomPersonality); if (RandomPersonality < 0.2f) { Personality = HenPersonalities.AGGRESSIVE; } if (RandomPersonality >= 0.2f && RandomPersonality < 0.5f) { Personality = HenPersonalities.COWARD; } if (RandomPersonality >= 0.5f && RandomPersonality < 0.9f) { Personality = HenPersonalities.PROTECTIVE; } if (RandomPersonality >= 0.9f) { Personality = HenPersonalities.UNLIKABLE; } CurrentStatus = HenStatus.ROAMING; movAgent = GetComponent <NavMeshAgent>(); // DT Decisions DTDecision decAnimationStop = new DTDecision(AnimationStop); DTDecision decDistantFromRooster = new DTDecision(DistantFromRooster); DTDecision decPlayerInFOV = new DTDecision(PlayerInFOV); DTDecision decPlayerInAttackRange = new DTDecision(PlayerInAttackRange); DTDecision decChickInAttackRange = new DTDecision(ChickInAttackRange); DTDecision decNearerToTheChick = new DTDecision(NearerToTheChick); DTDecision decCowardHen = new DTDecision(CowardHen); DTDecision decUnlikableHen = new DTDecision(UnlikableHen); DTDecision decProtectiveHen = new DTDecision(ProtectiveHen); // DT Actions DTAction actWait = new DTAction(Wait); DTAction actChaseRooster = new DTAction(ChaseRooster); DTAction actFlee = new DTAction(Flee); DTAction actProtect = new DTAction(Protect); DTAction actEngageChick = new DTAction(EngageChick); DTAction actEngagePlayer = new DTAction(EngagePlayer); DTAction actChasePlayer = new DTAction(ChasePlayer); DTAction actRoam = new DTAction(Roam); // DT Links decAnimationStop.AddLink(true, actWait); decAnimationStop.AddLink(false, decDistantFromRooster); decDistantFromRooster.AddLink(true, actChaseRooster); decDistantFromRooster.AddLink(false, decPlayerInFOV); decPlayerInFOV.AddLink(true, decCowardHen); decPlayerInFOV.AddLink(false, decUnlikableHen); decPlayerInAttackRange.AddLink(true, actEngagePlayer); decPlayerInAttackRange.AddLink(false, decProtectiveHen); decChickInAttackRange.AddLink(true, actEngageChick); decChickInAttackRange.AddLink(false, actRoam); decNearerToTheChick.AddLink(true, actProtect); decNearerToTheChick.AddLink(false, actChasePlayer); decCowardHen.AddLink(true, actFlee); decCowardHen.AddLink(false, decPlayerInAttackRange); decUnlikableHen.AddLink(true, decChickInAttackRange); decUnlikableHen.AddLink(false, actRoam); decProtectiveHen.AddLink(true, decNearerToTheChick); decProtectiveHen.AddLink(false, actChasePlayer); // Setup DT dt = new DecisionTree(decAnimationStop); }
private object Protect(object o) { CurrentStatus = HenStatus.PROTECTING; GetComponent <ProtectBehaviour>().ExecuteBehaviour(NearestChick); return(null); }
// Update is called once per frame void Update() { if (timer < 2f) { timer += Time.deltaTime; } if (timer > HensParametersManager.AttackTime) { if (Vector3.Distance(Rooster.transform.position, transform.position) > 5f) { CurrentStatus = HenStatus.CATCHINGUP; CatchUp(); } else { if ((Personality == HenPersonalities.AGGRESSIVE && Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenAggressiveFOV, NearbyPlayers, PlayersLayer) > 0) || Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenFOV, NearbyPlayers, PlayersLayer) > 0) { GetComponent <RoamingBehaviour>().ResetDirection(); NearestPlayer = FindNearest(NearbyPlayers); if ((Personality == HenPersonalities.PROTECTIVE && Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenProtectiveFOV, NearbyChicks, ChicksLayer) > 0)) { NearestChick = FindNearest(NearbyChicks); if (Vector3.Distance(transform.position, NearestChick.transform.position) < Vector3.Distance(NearestPlayer.transform.position, NearestChick.transform.position)) { if (Vector3.Distance(NearestPlayer.transform.position, transform.position) > HensParametersManager.HenAttackFOV) { CurrentStatus = HenStatus.PROTECTING; GetComponent <ProtectBehaviour>().ExecuteBehaviour(NearbyChicks); } else { timer = 0; CurrentStatus = HenStatus.ENGAGING; GetComponent <EngageBehaviour>().ExecuteBehaviour(NearbyPlayers); } } else { if (Vector3.Distance(NearestPlayer.transform.position, transform.position) > HensParametersManager.HenAttackFOV) { CurrentStatus = HenStatus.GOINGTO; GetComponent <GoToBehaviour>().ExecuteBehaviour(NearbyPlayers); } else { timer = 0; CurrentStatus = HenStatus.ENGAGING; GetComponent <EngageBehaviour>().ExecuteBehaviour(NearbyPlayers); } } } else if ((Personality == HenPersonalities.UNLIKABLE && Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenProtectiveFOV, NearbyChicks, ChicksLayer) > 0)) { NearestChick = FindNearest(NearbyChicks); if (Vector3.Distance(NearestChick.transform.position, transform.position) > HensParametersManager.HenAttackFOV) { CurrentStatus = HenStatus.GOINGTO; GetComponent <GoToBehaviour>().ExecuteBehaviour(NearbyChicks); } else { timer = 0; CurrentStatus = HenStatus.ENGAGING; GetComponent <EngageBehaviour>().ExecuteBehaviour(NearbyChicks); } } else { if ((Personality == HenPersonalities.COWARD) && Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenCowardFOV, NearbyHens, HensLayer) == 1) { CurrentStatus = HenStatus.FLEEING; GetComponent <FleeBehaviour>().ExecuteBehaviour(NearbyPlayers); } else { if (Vector3.Distance(NearestPlayer.transform.position, transform.position) > HensParametersManager.HenAttackFOV) { CurrentStatus = HenStatus.GOINGTO; GetComponent <GoToBehaviour>().ExecuteBehaviour(NearbyPlayers); } else { timer = 0; CurrentStatus = HenStatus.ENGAGING; GetComponent <EngageBehaviour>().ExecuteBehaviour(NearbyPlayers); } } } } else { Physics.OverlapSphereNonAlloc(transform.position, HensParametersManager.HenFOV, NearbyHens, HensLayer); CurrentStatus = HenStatus.ROAMING; GetComponent <RoamingBehaviour>().ExecuteBehaviour(NearbyHens); } } } }