public bool canFireToTarget(float maximumFiringDistance) { bool canFire = maximumFiringDistance > distanceTo(target.getCurrentPosition()); if (!canFire) { //Debug.Log("Distance Fail"); return(false); } else { RaycastHit hit; string[] layerMaskNames = { "FullCOverObsticles" }; if (Physics.Raycast(transform.position + new Vector3(0, 2f, 0), target.getTopPosition() - this.transform.position - new Vector3(0, 2f, 0), out hit, maximumFiringDistance, LayerMask.GetMask(layerMaskNames))) { return(false); } else { //Debug.Log("Nothing to hit"); return(true); } } }
public override void updateStage() { // This is needed for calling step update. base.updateStage(); m_selfAgent.setTargetPoint(m_opponent.getCurrentPosition() + m_randomTargetOffset); }
/** * Get target position of the current aimed agent */ private Vector3 getTargetPositionFromAgent() { MovingAgent humanoidAgent = m_currentTarget as MovingAgent; if (humanoidAgent == null) { return(m_currentTarget.getTopPosition()); } else { if (humanoidAgent.isCrouched()) { if (humanoidAgent.isAimed()) { return(m_currentTarget.getTopPosition()); } else { return(m_currentTarget.getCurrentPosition() + new Vector3(0, 0.6f, 0)); } } else { return(m_currentTarget.getCurrentPosition() + new Vector3(0, 1.05f, 0)); } } }
void OnDrawGizmos() { if (isOccupied()) { Gizmos.color = Color.green; Gizmos.DrawLine(this.transform.position, m_currentOccupent.getCurrentPosition()); } else { Gizmos.color = Color.cyan; } Gizmos.DrawCube(transform.position + new Vector3(0, 0.8f, 0), new Vector3(0.4f, 0.4f, 0.4f)); }
void OnDrawGizmos() { if (isOccupied()) { Gizmos.color = Color.black; Gizmos.DrawLine(this.transform.position, occupent.getCurrentPosition()); } else { Gizmos.color = Color.gray; } Gizmos.DrawSphere(transform.position + new Vector3(0, 0.3f, 0), 0.3f); //Gizmos.DrawCube(transform.position + new Vector3(0, 0.3f, 0), new Vector3(0.6f, 0.6f, 0.6f)); }
/** * Get the target agent closes to the aimed postion. ( interms of the angle) */ private ICyberAgent getNearestTargetAgent(Vector3 aimedPosition) { ICyberAgent tempAgent = null; float minAngle = 999; foreach (ICyberAgent target in m_targets) { if (target != null) { float angle = Vector3.Angle(target.getCurrentPosition() - m_selfPosition, aimedPosition - m_selfPosition); float distance = Vector3.Distance(target.getCurrentPosition(), m_selfPosition); if (angle < minAngle && angle < AUTO_FIRE_ANGLE && target.IsFunctional() && target.getName() != m_selfName && distance < FIRE_DISTANCE) { minAngle = angle; tempAgent = target; } } else { m_targets.Remove(target); } } if (tempAgent == null) { m_targetIndicator.transform.position = new Vector3(0, -10, 0); } else { m_targetIndicator.transform.localPosition = tempAgent.getCurrentPosition(); m_targetIndicatorColor.color = tempAgent.getHealthColor(); m_healthBar.setHealthPercentage(tempAgent.getHealthPercentage()); if (tempAgent.GetType() == typeof(FlyingAgent)) { m_targetIndicatorColor.enabled = false; } else { m_targetIndicatorColor.enabled = true; } } return(tempAgent); }
private void updateSubStages() { findTargetLocationToFire(); switch (currentCombatSubStage) { case CombatSubStages.InCover: //Debug.Log("In Cover"); m_selfAgent.lookAtTarget(); if (currentCoverPoint.isSafeFromTarget() && currentCoverPoint.canFireToTarget(fireRangeDistance)) { switch (currentCoverShootingSubStage) { case CoverShootingSubStages.Cover: m_selfAgent.aimWeapon(); currentCoverShootingSubStage = CoverShootingSubStages.Peek; shotsFromCover = (int)(Random.value * 5); //Debug.Log(shotsFromCover); break; case CoverShootingSubStages.Peek: m_selfAgent.weaponFireForAI(); currentCoverShootingSubStage = CoverShootingSubStages.Shoot; setStepIntervalSize(0.3f); break; case CoverShootingSubStages.Shoot: currentShotsFromCover++; if (currentShotsFromCover > shotsFromCover) { currentCoverShootingSubStage = CoverShootingSubStages.Cover; currentShotsFromCover = 0; m_selfAgent.stopAiming(); setStepIntervalSize(0.8f); } else { currentCoverShootingSubStage = CoverShootingSubStages.Peek; } break; } } else { //Debug.Log("Cover is not safe or cannot fire to target"); currentCombatSubStage = CombatSubStages.LookingForCover; setStepIntervalSize(1); } break; case CombatSubStages.LookingForCover: //Debug.Log("Looking for cover"); CoverPoint tempCurrentCoverPoint = closestCombatLocationAvaialbe(); if (tempCurrentCoverPoint != null) { if (currentCoverPoint) { //currentCoverPoint.stPointOccupentsName(""); currentCoverPoint.setOccupent(null); } currentCoverPoint = tempCurrentCoverPoint; m_navMeshAgent.SetDestination(currentCoverPoint.getPosition()); currentCombatSubStage = CombatSubStages.MovingToCover; // Get up and move m_selfAgent.toggleHide(); m_selfAgent.aimWeapon(); } break; case CombatSubStages.MovingToCover: //Debug.Log("Moving to cover"); if (!m_navMeshAgent.pathPending && m_navMeshAgent.remainingDistance > 1) { if (m_navMeshAgent.remainingDistance > 3 && Vector3.Distance(m_selfAgent.getCurrentPosition(), opponent.getCurrentPosition()) > fireRangeDistance) { m_enableRun = true; m_selfAgent.stopAiming(); } else { if (Vector3.Distance(m_selfAgent.getCurrentPosition(), opponent.getCurrentPosition()) < fireRangeDistance) { m_selfAgent.aimWeapon(); m_enableRun = false; m_selfAgent.weaponFireForAI(); } } } else { m_selfAgent.lookAtTarget(); currentCombatSubStage = CombatSubStages.InCover; // Get down on cover m_selfAgent.toggleHide(); m_selfAgent.stopAiming(); setStepIntervalSize(0.8f); m_navMeshAgent.velocity = Vector3.zero; } break; } }
public void updateTarget() { float minimumDistance = Vector3.Distance(m_selfAgent.getCurrentPosition(), opponent.getCurrentPosition()); if (opponent == null || !opponent.IsFunctional()) { minimumDistance = 9999; AgentController[] allAgents = GameObject.FindObjectsOfType <AgentController>(); foreach (AgentController agent in allAgents) { ICyberAgent cyberAgent = agent.getICyberAgent(); float distance = Vector3.Distance(m_selfAgent.getCurrentPosition(), cyberAgent.getCurrentPosition()); if (cyberAgent.IsFunctional() && cyberAgent.getFaction() != m_selfAgent.getFaction() && !cyberAgent.getFaction().Equals(AgentController.AgentFaction.Player)) { if (distance < minimumDistance) { minimumDistance = distance; opponent = cyberAgent; } } } } }