public override void UpdateComponent(float _DeltaTime) { base.UpdateComponent(_DeltaTime); if (!m_AICharacter) { return; } if (m_AICharacter.m_TargetCharacter) { return; } if (m_AICharacter.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.ATTACK) { m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.IDLE; m_AICharacter.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f); m_AICharacter.GetNavMeshController().ClearPath(); } if (m_AICharacter.GetAIState() != AICharacter.E_AIState.PATROL) { m_AICharacter.SetAIState(AICharacter.E_AIState.PATROL); } if (m_AICharacter.GetNavMeshController().IsUpdate()) { return; } if (m_PositionHoldingTimer > 0.0f) { m_PositionHoldingTimer -= _DeltaTime; return; } m_PositionHoldingTimer = m_AICharacter.GetAIData().PositionHoldingTime; float minradius = m_AICharacter.GetAIData().MinimumMovingRange; float maxradius = m_AICharacter.GetAIData().MaxmumMovingRange; float findrange = maxradius - minradius; Vector3 nextlocation = new Vector3(Random.Range(-findrange, findrange), 0.0f, Random.Range(-findrange, findrange)); nextlocation.x += nextlocation.x < 0.0f ? -minradius : minradius; nextlocation.z += nextlocation.z < 0.0f ? -minradius : minradius; m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.transform.position + nextlocation); }
public override void UpdateComponent(float _DeltaTime) { base.UpdateComponent(_DeltaTime); if (!m_AICharacter) { return; } if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD) { if (m_AICharacter.m_UpperAnimState == CharacterBase.E_UpperBodyAnimState.ATTACK) { m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.DEATH; m_AICharacter.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f); } return; } if (!m_AICharacter.m_TargetCharacter) { return; } if (m_AICharacter.GetAIState() != AICharacter.E_AIState.ATTACK) { return; } if (m_AICharacter.m_UpperAnimState != CharacterBase.E_UpperBodyAnimState.ATTACK) { m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.ATTACK; m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimGunAttackKey, 0.1f * GameManager.Instance.TimeScale); m_AttackDelay = 0.1f; } if (m_AttackDelay > 0.0f) { m_AttackDelay -= _DeltaTime; return; } m_AttackDelay = m_AICharacter.GetAIData().AttackDelay; if (m_AICharacter.GetAIData().Belligerence < (1.0f - Random.Range(0.0f, 1.0f))) { m_AttackDelay += m_AICharacter.GetAIData().Belligerence *(1.0f - Random.Range(0.0f, 1.0f)); } Vector3 upperbodyDir = m_AICharacter.GetUpperBodyDirection(); Vector3 upperbodyDirNormal = upperbodyDir.normalized; Vector3 targetDir = m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position; float tdistance = targetDir.magnitude; float d = Vector3.Dot(upperbodyDirNormal, targetDir.normalized); if (d > 0.95f && tdistance <= m_AICharacter.GetAIData().AttackRange) { if (Physics.Raycast(m_AICharacter.GetBodyPositionWithWorld(), upperbodyDirNormal, tdistance * 0.3f, m_ObstacleLayerMask)) { foreach (Gun g in m_CharacterBase.GetGuns()) { g.GunShotDisable(); } return; } foreach (Gun g in m_CharacterBase.GetGuns()) { g.GunShotActivate(); } for (int i = 0; i < m_AICharacter.GetGunAttachCount(); ++i) { BulletSystem.CreateBullet(m_AICharacter.GetGun(i).GetFirePoint().position, 1.0f, m_AICharacter.m_CharacterID, E_BulletType.ORANGE, 1, upperbodyDir, 30.0f, m_TargetLayerMask, 5); } SoundManager.Instance.PlayInstanceSound(m_CharacterBase.GetGun(0).GetFirePoint().position, m_CharacterBase.GetGun(0).GetFireSound()); } else { foreach (Gun g in m_CharacterBase.GetGuns()) { g.GunShotDisable(); } } }
public override void UpdateComponent(float _DeltaTime) { base.UpdateComponent(_DeltaTime); if (!m_AICharacter) { return; } if (!m_AICharacter.m_TargetCharacter) { return; } if (m_AICharacter.m_TargetCharacter.m_Live == CharacterBase.E_Live.DEAD) { m_AICharacter.m_TargetCharacter = null; m_AICharacter.GetNavMeshController().ClearPath(); foreach (Gun g in m_CharacterBase.GetGuns()) { g.GunShotDisable(); } return; } if (m_HoldTimer > 0.0f) { m_HoldTimer -= _DeltaTime; } if (m_UpdateDelayTimeTimer > 0.0f) { m_UpdateDelayTimeTimer -= _DeltaTime; if (m_UpdateDelayTimeTimer > 0.0f) { return; } } m_UpdateDelayTimeTimer = m_UpdateDelayTime; Vector3 direction = m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position; float distance = direction.magnitude; if (m_AICharacter.GetAIData().AttackRange < distance) { m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.m_TargetCharacter.transform.position); m_AICharacter.m_UpperAnimState = CharacterBase.E_UpperBodyAnimState.IDLE; m_CharacterBase.m_Animator.CrossFade(CharacterBase.m_AnimIdleKey, 0.1f); m_AICharacter.SetAIState(AICharacter.E_AIState.CHASE); foreach (Gun g in m_CharacterBase.GetGuns()) { g.GunShotDisable(); } } else { if (m_AICharacter.GetAIState() != AICharacter.E_AIState.ATTACK) { m_AICharacter.SetAIState(AICharacter.E_AIState.ATTACK); m_AICharacter.GetNavMeshController().ClearPath(); } if (m_AICharacter.GetNavMeshController().IsUpdate()) { return; } if (m_HoldTimer > 0.0f) { return; } m_HoldTimer = Random.Range(m_AICharacter.GetAIData().PositionHoldingTime * 0.3f, m_AICharacter.GetAIData().PositionHoldingTime); float angle = m_AICharacter.transform.eulerAngles.y; float b = m_AICharacter.GetAIData().Belligerence; float offset = (distance / m_AICharacter.GetAIData().AttackRange) * b * 90.0f; float fixedAngle = angle + Random.Range(-offset, offset); angle += angle < fixedAngle ? -(100.0f - offset) : 100.0f - offset; if (angle > 360.0f) { angle -= 360.0f; } else if (angle < 0.0f) { angle += 360.0f; } Vector3 fwd = Quaternion.AngleAxis(angle, Vector3.up) * Vector3.forward; float minrange = m_AICharacter.GetAIData().MinimumMovingRange; float travelDistance = Random.Range(minrange > 0.5f ? minrange : 0.5f, m_AICharacter.GetAIData().MaxmumMovingRange); m_AICharacter.GetNavMeshController().SetMoveLocation(m_AICharacter.transform.position, m_AICharacter.transform.position + fwd * travelDistance); } }