private void Update() { if (GameManager.Instance.m_Main.m_GamePause) { return; } if (!m_Target) { return; } if (m_Target.m_Live == CharacterBase.E_Live.LIVE) { return; } m_SpawnTimer -= Time.deltaTime * GameManager.Instance.TimeScale; if (m_SpawnTimer <= 0.0f) { m_Target.transform.position = m_Target.GetNavMeshController().FindNavMeshSampleLocation(transform.position, 1.0f); m_Target.Revive(); m_SpawnTimer = m_SpawnDelay; } }
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.GetNavMeshController().IsUpdate()) { m_AICharacter.GetNavMeshController().ClearPath(); } return; } if (m_CharacterBase.m_UnderAnimState == CharacterBase.E_UnderBodyAnimState.JUMP) { return; } if (!m_AICharacter.GetNavMeshController().IsUpdate()) { if (m_AICharacter.m_UnderAnimState == CharacterBase.E_UnderBodyAnimState.RUN) { m_AICharacter.m_Animator.SetFloat("DirectionX", 0.0f); m_AICharacter.m_Animator.SetFloat("DirectionY", 0.0f); m_AICharacter.m_UnderAnimState = CharacterBase.E_UnderBodyAnimState.LAND; } return; } if (m_AICharacter.m_UnderAnimState != CharacterBase.E_UnderBodyAnimState.RUN) { m_AICharacter.m_UnderAnimState = CharacterBase.E_UnderBodyAnimState.RUN; m_AICharacter.m_Animator.CrossFade(CharacterBase.m_UpperBodyTreeKey, 0.1f); } Vector3 dir = m_AICharacter.GetNavMeshController().GetCurrentPathDirection(m_CharacterBase.transform).normalized; m_AICharacter.m_Animator.SetFloat("DirectionX", dir.x); m_AICharacter.m_Animator.SetFloat("DirectionY", dir.z); m_AICharacter.GetNavMeshController().UpdateTransform(m_CharacterBase.transform, m_AICharacter.GetAIData().MoveSpeed, m_RotatePerSpeed, _DeltaTime); }
private IEnumerator Start() { while (GameManager.Instance.m_Main.m_GamePause) { yield return(null); } GameObject g = Instantiate(m_Prefab, transform.position, Quaternion.identity); if (g) { m_Target = g.GetComponent <AICharacter>(); if (m_Target == null) { Destroy(g); gameObject.SetActive(false); } m_Target.transform.position = m_Target.GetNavMeshController().FindNavMeshSampleLocation(transform.position, 1.0f); } m_SpawnTimer = m_SpawnDelay; }
public override void UpdateComponent(float _DeltaTime) { base.UpdateComponent(_DeltaTime); if (!m_AICharacter) { return; } if (m_AICharacter.m_Live == CharacterBase.E_Live.DEAD) { return; } float rotValue = m_RotatePerSpeed * _DeltaTime; Vector3 rot = m_AICharacter.transform.eulerAngles; Vector3 focusingdir = Vector3.zero; if (m_AICharacter.m_TargetCharacter) { Vector3 dir = (m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position).normalized; Vector3 cdir = dir; cdir.y = 0.0f; float dirAngle = Vector3.Angle(cdir, dir); m_AICharacter.SetUpperBodyAngleX(dir.y < 0.0f ? -dirAngle : dirAngle); m_AICharacter.UpperBodyYAngleOffsetPercentage = dir.magnitude / m_AICharacter.GetAIData().AttackRange; focusingdir = (m_AICharacter.m_TargetCharacter.transform.position - m_AICharacter.transform.position).normalized; } else if (m_AICharacter.GetNavMeshController().IsUpdate()) { focusingdir = m_AICharacter.GetNavMeshController().GetCurrentPathDirection(m_AICharacter.transform).normalized; } if (focusingdir == Vector3.zero) { return; } float dot = Vector3.Dot(m_AICharacter.transform.right, focusingdir); Vector3 dirRot = Quaternion.LookRotation(focusingdir).eulerAngles; if (Mathf.Abs(dirRot.y - rot.y) > rotValue) { if (dot < 0.0f) { rot.y -= rotValue; } else { rot.y += rotValue; } } else { rot.y = dirRot.y; } rot.y = rot.y % 360.0f; m_AICharacter.transform.eulerAngles = rot; }
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); } }