private bool ComparePosition(AIEnemyData enemy) { for (int i = 0; i < enemyData.Count; i++) { if (enemyData[i].enemyId != enemy.enemyId) { if (Vector3.Distance(enemy.targetPosition, enemyData[i].targetPosition) < separationDistance) { return(false); } } } return(true); }
public void Remove(AIEnemyData enemy) { removingEnemy = true; if (enemyData.Count > 0) { for (int i = 0; i < enemyData.Count; i++) { if (enemyData[i].enemyId == enemy.enemyId) { enemyData.RemoveAt(i); } } } removingEnemy = false; }
public virtual void OnDeath() { if (!will.isDead) { EventSystem.Instance.TriggerEvent(Strings.Events.DEATH_ENEMY, gameObject, scoreValue); will.isDead = true; if (will.willHasBeenWritten) { will.onDeath(); } if (!aboutTobeEaten) { GameObject mallCopParts = ObjectPool.Instance.GetObject(PoolObjectType.VFXMallCopExplosion); if (mallCopParts) { SFXManager.Instance.Play(SFXType.BloodExplosion, transform.position); mallCopParts.transform.position = transform.position + Vector3.up * 3f; mallCopParts.transform.rotation = transform.rotation; } } else { gibEmitter.Emit(); } navAgent.speed = 0; navAgent.enabled = false; aboutTobeEaten = false; alreadyStunned = false; isIndestructable = false; SFXManager.Instance.Play(deathSFX, transform.position); AIEnemyData testData = new AIEnemyData(controller.GetInstanceID()); currentStunTime = 0.0f; if (AIManager.Instance != null) { AIManager.Instance.Remove(testData); } ClearAffecters(); gameObject.SetActive(false); } }
public bool AssignPosition(AIEnemyData enemy) { if (!removingEnemy) { //Check if the list is empty if (enemyData.Count < 1) { enemyData.Add(enemy); return(true); } //Enemy in the list else if (enemyData.Count >= 1) { bool enemyFound = false; for (int i = 0; i < enemyData.Count; i++) { if (enemyData[i].enemyId == enemy.enemyId) { enemyData[i].targetPosition = enemy.targetPosition; enemyFound = true; } } if (!enemyFound) { enemyData.Add(enemy); } return(ComparePosition(enemy)); } //Enemy is not in the list else { return(true); } } return(false); }
private void GetNewChaseTarget() { Vector3 moveDirection = controller.DirectionToTarget; jumpTarget = controller.transform.position + (moveDirection.normalized * jumpTargetDistance); Vector3 fwd = controller.DirectionToTarget; RaycastHit hit; //Do a ray cast to check there is no obstruction if (Physics.Raycast(controller.transform.position, fwd, out hit, Mathf.Infinity, LayerMask.GetMask(Strings.Layers.MODMAN, Strings.Layers.OBSTACLE))) { if (hit.transform.tag == Strings.Tags.PLAYER) { //Special case when a wall is behind the player if (Physics.Raycast(controller.AttackTargetPosition, fwd, out hit, 5)) { if (hit.transform.tag == Strings.Tags.WALL) { if (Vector3.Distance(controller.transform.position, controller.AttackTargetPosition) < jumpTargetDistance) { if (navAgent.SetDestination(controller.AttackTargetPosition + (-controller.DirectionToTarget.normalized) * 1.5f)) { finalPosition = controller.AttackTargetPosition + (-controller.DirectionToTarget.normalized) * 1.5f; } } else { if (navAgent.SetDestination(jumpTarget)) { finalPosition = jumpTarget; } } } else { if (navAgent.SetDestination(controller.AttackTargetPosition)) { finalPosition = controller.AttackTargetPosition; } } } else { if (navAgent.SetDestination(jumpTarget)) { finalPosition = jumpTarget; } } } //Hit obstacle else { if (Vector3.Distance(controller.transform.position, controller.AttackTargetPosition) < jumpTargetDistance) { if (navAgent.SetDestination(controller.AttackTargetPosition)) { finalPosition = controller.AttackTargetPosition; } } else { Vector3 bouncerPos = new Vector3(controller.transform.position.x, controller.transform.position.y, controller.transform.position.z); Vector3 closestPoint = hit.collider.ClosestPointOnBounds(bouncerPos); float newDistance = Vector3.Distance(closestPoint, bouncerPos); if (newDistance < jumpTargetDistance) { jumpTarget = controller.transform.position + (moveDirection.normalized * (jumpTargetDistance + hit.collider.bounds.extents.magnitude * 1.2f)); if (navAgent.SetDestination(jumpTarget)) { finalPosition = jumpTarget; } } else { if (navAgent.SetDestination(jumpTarget)) { finalPosition = jumpTarget; } } } } } AIEnemyData testData = new AIEnemyData(controller.GetInstanceID(), finalPosition); if (AIManager.Instance != null) { if (AIManager.Instance.AssignPosition(testData)) { //Debug.Log("Normal"); moving = true; Timing.RunCoroutine(Move(), CoroutineName); } else { //Debug.Log("Readjusted"); finalPosition = controller.transform.position + Random.insideUnitSphere * jumpTargetDistance / 2; finalPosition.y = controller.transform.position.y; moving = true; Timing.RunCoroutine(Move(), CoroutineName); } } else { //Debug.Log("Readjusted"); finalPosition = controller.transform.position + Random.insideUnitSphere * jumpTargetDistance / 2; finalPosition.y = controller.transform.position.y; moving = true; Timing.RunCoroutine(Move(), CoroutineName); } }