/** * 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)); } } }
private void findTargetLocationToFire() { MovingAgent humanoidOpponent = opponent as MovingAgent; if (humanoidOpponent != null && humanoidOpponent.isCrouched() && humanoidOpponent.isAimed()) { targetLocation = humanoidOpponent.getHeadTransfrom(); } else { int randomIndex = Random.Range(0, targetLocations.Length - 1); targetLocation = targetLocations[randomIndex].transform; } if (Random.value > m_selfAgent.getSkill()) { randomOffset = Random.insideUnitSphere * 2; } else if (m_navMeshAgent.remainingDistance > 9) { randomOffset = Random.insideUnitSphere * 0.7f; } else { randomOffset = Vector3.zero; } }
protected void updateSelfAgentFromInput() { #region get control input float inputHorizontal = SimpleInput.GetAxis("Horizontal"); float inputVertical = SimpleInput.GetAxis("Vertical"); float aimInputHorizontal = SimpleInput.GetAxis("HorizontalAim"); float aimInputVertical = SimpleInput.GetAxis("VerticalAim"); Vector3 aimDirection = getDirectionRelativeToCamera(new Vector3(aimInputVertical, 0, -aimInputHorizontal)); bool runPressed = SimpleInput.GetButton("Run"); bool crouchPressed = SimpleInput.GetButtonDown("Crouch"); bool dodge = SimpleInput.GetButtonDown("Dodge"); bool rifle = SimpleInput.GetButtonDown("Rifle"); bool pistol = SimpleInput.GetButtonDown("Pistol"); #endregion #region control agent from input #region movment control if (rifle) { m_selfAgent.togglePrimaryWeapon(); } if (pistol) { m_selfAgent.togglepSecondaryWeapon(); } if (crouchPressed) { m_selfAgent.toggleHide(); m_crouched = !m_crouched; } if (dodge) { m_selfAgent.dodgeAttack(getDirectionRelativeToCamera((new Vector3(inputVertical, 0, -inputHorizontal).normalized) * 1.5f)); } if (runPressed) { if (m_selfAgent.isCrouched()) { m_selfAgent.toggleHide(); } m_selfAgent.moveCharacter(getDirectionRelativeToCamera((new Vector3(inputVertical, 0, -inputHorizontal).normalized) * 1.5f)); } else { if (m_crouched && !m_selfAgent.isCrouched()) { m_selfAgent.toggleHide(); } m_selfAgent.moveCharacter(getDirectionRelativeToCamera(new Vector3(inputVertical, 0, -inputHorizontal).normalized)); } #endregion #region aiming and fire control if (aimDirection.normalized.magnitude > 0) { m_selfAgent.aimWeapon(); m_targetFinder.updateTargetFinder(aimDirection, this.transform.position); m_selfAgent.setTargetPoint(m_targetFinder.getCalculatedTargetPosition()); if (m_targetFinder.canFireAtTargetAgent()) { m_selfAgent.pullTrigger(); } else { m_selfAgent.releaseTrigger(); } } else { m_selfAgent.stopAiming(); m_selfAgent.releaseTrigger(); m_targetFinder.disableTargetIndicator(); } #endregion #endregion }