public virtual void Aggrevate() { if (_aiHealth.IsDead) { return; } //Move the last known location to the players position when the player shoots. _lastKnownLocation.transform.position = _player.position; _isAggrevated = true; if (stateMachine == null) { stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIDeathState(this)); stateMachine.RegisterState(new AIIdleState(this)); stateMachine.RegisterState(new AICombatState(this)); stateMachine.RegisterState(new AISearchForPlayerState(this)); stateMachine.RegisterState(new AICheckPlayerState(this)); stateMachine.RegisterState(new AIMeleeState(this)); if (_startingWeapon) { RaycastWeapon weapon = Instantiate(_startingWeapon.Weapon); _aiWeapon = GetComponent <AIWeapons>(); _aiWeapon.EquipWeapon(weapon); } } stateMachine.ChangeState(AiStateId.CombatState); }
private void Start() { //Gets the animator Animator anim = GetComponent <Animator>(); //Initalizes the bone transforms array _boneTransforms = new Transform[_humanBones.Length]; //Cycles through the length for (int i = 0; i < _boneTransforms.Length; i++) { //Gets the transforms of the desired bones _boneTransforms[i] = anim.GetBoneTransform(_humanBones[i].bone); } //Gets the weapon _aiWeapon = GetComponent <AIWeapons>(); //if we have a weapon if (_aiWeapon.HasWeapon()) { //Stores the weapon transform _weaponTransform = GetComponentInChildren <RaycastWeapon>().transform; } }
public void Initialize(AIAgent agent) { _aiWeapon = agent.GetComponent <AIWeapons>(); _navAgent = agent.GetComponent <NavMeshAgent>(); _aiHealth = agent.GetComponent <AIHealth>(); _fov = agent.GetComponent <FieldOfView>(); _lastKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>(); _agent = agent; }
public void Initialize(AIAgent agent) { _navAgent = agent.GetComponent <NavMeshAgent>(); _aiHealth = agent.GetComponent <AIHealth>(); _aiWeapon = agent.GetComponent <AIWeapons>(); _coversInZone = agent.GetComponentInParent <CombatZone>().CoversInZone.ToArray(); _anim = agent.GetComponent <Animator>(); _agent = agent; }
private void OnTriggerEnter(Collider other) { ActiveWeapon activeWeapon = other.gameObject.GetComponent <ActiveWeapon>(); if (activeWeapon) { RaycastWeapon newWeapon = Instantiate(weaponFab); activeWeapon.Equip(newWeapon); Destroy(gameObject); } AIWeapons aiWepons = other.gameObject.GetComponent <AIWeapons>(); if (aiWepons) { RaycastWeapon newWeapon = Instantiate(weaponFab); aiWepons.Equip(newWeapon); Destroy(gameObject); } }
// Start is called before the first frame update void Start() { //Find the player if (!_player) { _player = GameObject.FindGameObjectWithTag("Player").transform; } stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIDeathState(this)); stateMachine.RegisterState(new AIIdleState(this)); stateMachine.RegisterState(new AICombatState(this)); stateMachine.RegisterState(new AISearchForPlayerState(this)); stateMachine.RegisterState(new AICheckPlayerState(this)); stateMachine.RegisterState(new AIMeleeState(this)); //Registers the patrol state if we have a patrol route if (_route) { stateMachine.RegisterState(new PatrolState(this, _route, _movementSpeedInPatrol, _waitAtEachPointDuration)); } //If we have a starting weapon then instantiate and equip it if (_startingWeapon) { RaycastWeapon weapon = Instantiate(_startingWeapon.Weapon); _aiWeapon = GetComponent <AIWeapons>(); _aiWeapon.EquipWeapon(weapon); } else { Debug.LogError(transform.name + " has no starting weapon"); } stateMachine.ChangeState(_initialState); if (_initialState == AiStateId.CombatState) { Aggrevate(); } }
void Start() { //AI DEATH STATE ragdoll = GetComponent <Ragdoll>(); mesh = GetComponentInChildren <SkinnedMeshRenderer>(); healthBar = GetComponentInChildren <UIHealthBar>(); playerTransform = GameObject.FindGameObjectWithTag("Player").transform; navMeshAgent = GetComponent <NavMeshAgent>(); weapons = GetComponent <AIWeapons>(); stateMachine = new AIStateMachine(this); stateMachine.RegisterState(new AIChasePlayerState()); stateMachine.RegisterState(new AIDeathState()); stateMachine.RegisterState(new AIIdleState()); stateMachine.RegisterState(new AIFindWeaponState()); stateMachine.RegisterState(new AIAttackPlayerState()); stateMachine.ChangeState(initialState); rb = GetComponent <Rigidbody>(); }
public void Initialize(AIAgent agent) { _aiWeapon = agent.GetComponent <AIWeapons>(); _agent = agent; }
private IEnumerator SpawnEnemiesCoroutine() { yield return(new WaitForSeconds(spawnBeginningWait)); while (numEnemiesLeft > 0) { if (!recalculationFinished) { yield return(new WaitForSeconds(0.5f)); continue; } //Chose an amount of enemies to spawn at a time int numEnemiesToSpawn = (int)Random.Range(1, maxEnemiesSpawnAtTime); for (int index = 0; index < numEnemiesToSpawn; index++) { //Choose enemy to spawn GameObject enemyToSpawn = enemyClass.NextObject(); yield return(null); //Spawn enemy GameObject newEnemy = SpawnInWave(enemyToSpawn); numEnemiesLeft--; yield return(null); //Set different enemy guns if alien if (newEnemy.CompareTag("Alien")) { AIWeapons weapons = newEnemy.GetComponent <AIWeapons>(); GunDefinition[] guns = null; if (weapons != null) { guns = weapons.guns; } else { weapons = newEnemy.GetComponentInChildren <AIWeapons>(); guns = weapons.guns; } //TODO: correct implementation for (int gunIndex = 0; gunIndex < guns.Length; gunIndex++) { //Choose random gun GameObject gunToSet = enemyWeaponClass.NextObject(); yield return(null); guns[gunIndex].ChangeWeapon(gunToSet); yield return(null); } } yield return(new WaitForSeconds(enemyClass.NextWaitTime())); //pause } } //advance when no more enemies exist continueSpawningAsteroids = false; yield return(new WaitForSeconds(5)); manager.AdvanceLevel(); }
public AIDeathState(AIAgent agent) { _ragdoll = agent.GetComponent <Ragdoll>(); _aiWeapon = agent.GetComponent <AIWeapons>(); _navAgent = agent.GetComponent <NavMeshAgent>(); }