private void ForceTargetOnPlayer(Character c) { // pick a target int r = UnityEngine.Random.Range(0, Global.Lobby.PlayersInLobbyCount - 1); Character c2 = Global.Lobby.PlayersInLobby.ElementAt(r).ControlledCharacter; c.TargetingSystem.SetLockingPoint(c2.LockingPoint); // force combat AI state if (c.GetComponentInChildren <CharacterAI>() is CharacterAI chai) { chai.SetDestination(c2.transform.position, false); chai.CurrentLookTarget = c2.transform.position; chai.CurrentMoveTarget = c2.transform.position; for (int i = 0; i < chai.AiStates.Count(); i++) { if (chai.AiStates[i] is AISCombat AICombat) { // force combat target AICombat.OutOfSightRange = 9999; AICombat.SetPreferredTarget(c2.LockingPoint, 0); AICombat.SetMoveToPosition(c2.transform.position); chai.SwitchAiState(i); AICombat.gameObject.SetActive(true); } else { chai.AiStates[i].gameObject.SetActive(false); } } } }
// Use this for initialization void Start() { _player = GetComponent<Player> (); _AISystem = GameObject.FindGameObjectWithTag (Tags.GAMECONTROLLER).GetComponent<AISystemManager> (); _grid = new Grid (_AISystem.prefabGridList); _movement = gameObject.AddComponent<AIMovement> (); _combat = gameObject.AddComponent<AICombat> (); _targetLocator = gameObject.AddComponent<AITargetPrioritizer> (); _movement.SetLevelGrid (_grid); }
private void Start() { //Finds the NavMesh component attached to the slime navMesh = GetComponent <NavMeshAgent>(); renderer = GetComponent <Renderer>(); anim = GetComponent <Animator>(); rigidbody = GetComponent <Rigidbody>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); playerRef = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerCombat>(); combatScript = GameObject.Find("CombatArea").GetComponent <AICombat>(); navMesh.SetDestination(GetNewPos()); renderer.material = outOfCombatMaterial; currentHealth = maxHealth; healthBar.SetMaxHealth(maxHealth); }
public void Setup(HumanSheet humanSheetIn, bool isZombie, GameObject squadDeployment = null) { this.humanSheet = humanSheetIn; this.isZombie = isZombie; animator = transform.parent.GetComponent <Animator> (); stateMachine = transform.parent.GetComponent <AnimationStateMachine> (); stateMachine.Setup(this); animationEvents = transform.parent.GetComponent <AnimationEvents> (); animationEvents.Setup(this); agent = transform.parent.GetComponent <NavMeshAgent> (); navigation = GetComponent <AINavigation> (); navigation.Setup(showAgent); senses = GetComponent <AISenses> (); senses.Setup(); vision = transform.parent.GetComponentInChildren <AIVision> (); vision.Setup(this, showVisionTargets, showNearVision, showMidVision, showFarVision); combat = GetComponent <AICombat> (); combat.Setup(this); if (isZombie) { //Debug.Log ("zombie perception : " + humanSheet.stats.perception); motor = new ZombieMotor(this, transform.parent.GetComponent <Animator> ()); behaviourTree = new BTZombie(); } else { //Debug.Log ("swat perception : " + humanSheet.stats.perception); motor = new HumanMotor(this, transform.parent.GetComponent <Animator> ()); behaviourTree = new BTSwat(); } behaviourTree.squadDeployment = squadDeployment; behaviourTree.Setup(humanSheet, this); //motor.UpdateAvatarMask (); agent.updatePosition = false; //agent.updateRotation = false; behaviourTree.StartTree(); }