public void UpdateAnimation() { //11 l //12 r //13 f //14 b Vector3 d1 = _owner.ACOwner.ThisTransform.forward; float angle = Vector3.Angle(_owner.ACOwner.MoveDirection, d1); if (angle > 150) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleB1; if (_hDirection != HES_DIRECTION.BACK) { _hDirection = HES_DIRECTION.BACK; _owner.ACOwner.ACPlayAnimation(_aniSwitch); } } else if (angle < 30) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleF1; if (_hDirection != HES_DIRECTION.FORWARD) { _hDirection = HES_DIRECTION.FORWARD; _owner.ACOwner.ACPlayAnimation(_aniSwitch); } } else { d1.Normalize(); float zz = d1.z * _owner.ACOwner.MoveDirection.x - d1.x * _owner.ACOwner.MoveDirection.z; if (zz < 0) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleR1; if (_hDirection != HES_DIRECTION.RIGHT) { _hDirection = HES_DIRECTION.RIGHT; _owner.ACOwner.ACPlayAnimation(_aniSwitch); } } else { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleL1; if (_hDirection != HES_DIRECTION.LEFT) { _hDirection = HES_DIRECTION.LEFT; _owner.ACOwner.ACPlayAnimation(_aniSwitch); } } } }
private IEnumerator IDLE() { _owner.ACStop(); if (_usedForFly) { _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); } else { _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.UNLOCK); } ///play idle animations _aniSwitch._aniIdx = FC_All_ANI_ENUM.idle; _owner.ACPlayAnimation(_aniSwitch); _owner.ACAniSpeedRecoverToNormal(); _hDirection = HES_DIRECTION.NONE; //need idle min and max to GD _seekTime = Random.Range(0, 1f); _inSeek = true; while (_inSeek) { UpdateFaceTarget(); _seekTime -= Time.deltaTime; if (_seekTime <= 0) { float ret = Random.Range(0, 1f); //show chance to GD if (ret < 0.9f) { SetNextSeekMode(SEEK_MODE.WANDER_TO_PLAYER); } else { SetNextSeekMode(SEEK_MODE.COPY_PLAYER); } _owner.ACStop(); } UpdateAnimation(); yield return(null); } ChangeToSeekMode(); }
private IEnumerator FEINT_ATTACK() { _inSeek = true; int frameCount = 0; _owner.ACStop(); _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); _owner.ACSetMoveMode(MoveAgent.MOVE_MODE.BY_ANIMATION); //play fake attack _hDirection = HES_DIRECTION.NONE; _aniSwitch._aniIdx = FC_All_ANI_ENUM.fakeAttack0; _owner.ACPlayAnimation(_aniSwitch); while (_inSeek) { UpdateFaceTarget(); frameCount++; if (frameCount > 10 && _owner.AniGetAnimationNormalizedTime() > 0.35f) { Vector3 v3 = _targetAC.ThisTransform.localPosition - _owner.ThisTransform.localPosition; FCSkillConfig ews = _attackCountAgent.GetSkillAt(v3); if (ews != null) { SetNextSeekMode(SEEK_MODE.COPY_PLAYER); } else { GoToAttack(); } } UpdateAnimation(); yield return(null); } _owner.ACSetMoveMode(MoveAgent.MOVE_MODE.BY_MOVE_MANUAL); ChangeToSeekMode(); }
private IEnumerator RUN_AWAY_AFTER_ATTACK() { if (_usedForFly) { _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); } else { _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.UNLOCK); } Vector3 v3 = _owner.ThisTransform.localPosition - _targetAC.ThisTransform.localPosition; v3.y = 0; v3.Normalize(); if (v3 == Vector3.zero) { v3 = -_owner.ThisTransform.forward; } float angle = Random.Range(-10, 10); if (angle < 0) { angle -= 90; } else { angle += 90; } Quaternion qt = Quaternion.Euler(0, angle, 0); _owner.ACRotateTo(v3, -1, false); v3 = qt * v3; //need to show min and max to GD _seekTime = Random.Range(_awayAttackTimeMin, _awayAttackTimeMax); v3.Normalize(); _owner.CurrentSpeed = _wanderSpeed; MoveByDirection(v3, _wanderSpeed, _seekTime); _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleB1; _hDirection = HES_DIRECTION.BACK; _owner.ACPlayAnimation(_aniSwitch); _inSeek = true; while (_inSeek) { UpdateFaceTarget(); _seekTime -= Time.deltaTime; if (_seekTime <= 0) { float ret = Random.Range(0, 1f); if (ret < 1 - _awayAttackChanceToWanderSimple) { SetNextSeekMode(SEEK_MODE.WANDER_TO_PLAYER); } else { SetNextSeekMode(SEEK_MODE.WANDER_BY_SIMPLE_PATH); } } UpdateAnimation(); yield return(null); } ChangeToSeekMode(); }
//when after hurt ,enemy try to far from player private IEnumerator RUN_AWAY_AFTER_HURT() { _inSeek = true; _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); Vector3 v3 = _owner.ThisTransform.localPosition - _targetAC.ThisTransform.localPosition; v3.y = 0; v3.Normalize(); if (v3 == Vector3.zero) { v3 = -_owner.ThisTransform.forward; } float angle = Random.Range(-10, 10); if (angle < 0) { angle -= 90; } else { angle += 90; } Quaternion qt = Quaternion.Euler(0, angle, 0); _owner.ACRotateTo(v3, -1, false); v3 = qt * v3; _seekTime = Random.Range(_awayHurtTimeMin, _awayHurtTimeMax); v3.Normalize(); //monster will not rotate to final direction right now, instead with angle speed _owner.CurrentSpeed = _wanderSpeed; _owner.ACMoveToDirection(ref v3, 180, _seekTime); //play run animations _aniSwitch._aniIdx = FC_All_ANI_ENUM.run; _hDirection = HES_DIRECTION.NONE; _owner.ACPlayAnimation(_aniSwitch); while (_inSeek) { if (_seekTime > 0) { _seekTime -= Time.deltaTime; if (_seekTime <= 0) { _owner.ACStop(); SetNextSeekMode(SEEK_MODE.WANDER_TO_PLAYER); } //at end of this action, monster need try to face to player else if (_seekTime <= 1) { v3 = _targetAC.ThisTransform.localPosition - _owner.ThisTransform.localPosition; v3.y = 0; v3.Normalize(); angle = Vector3.Angle(_owner.ThisTransform.forward, v3); //16 is a magic num , means monster face near to player if (angle <= 16) { _seekTime = Random.Range(0.2f, 0.4f); SetNextSeekMode(SEEK_MODE.IDLE); _owner.ACStop(); } else { _owner.CurrentSpeed = _wanderSpeed / 2; _owner.ACMoveToDirection(ref v3, 360); } } } UpdateAnimation(); yield return(null); } ChangeToSeekMode(); }
public override void HesitateTaskChange(FCCommand.CMD cmd) { if (cmd == FCCommand.CMD.STATE_ENTER) { _timeTotalForWander = 0; _dangerousRaduisSqrt = _dangerousRaduis * _dangerousRaduis; _wanderSpeed = _owner.Data.TotalMoveSpeed * _wanderSpeedPercents; _hDirection = HES_DIRECTION.NONE; _realSafeDistance = _safeDistance + _bodyRadius + _targetAC.BodyRadius; _safeDistanceSqrt = _realSafeDistance * _realSafeDistance; _owner.ACSetMoveMode(MoveAgent.MOVE_MODE.BY_MOVE_MANUAL); _wantToAttack = false; _timeForWander = Random.Range(_timeForWanderMin, _timeForWanderMax); //CountTargetToSetWay(); float ret = Random.Range(0, 1f); if (_awayFromTarget == AWAY_MODE.AWAY_AFTER_HURT) { if (RageIsFull) { if (CanAttackOthers) { GoToAttack(); } else { if (!_haveActionTicket) { FCTicketManager.Instance.ApplyTicket(_owner); } } } else if (ret < _chanceToAwayAfterHurt) { SetNextSeekMode(SEEK_MODE.RUN_AWAY_AFTER_HURT); } else { SetNextSeekMode(SEEK_MODE.WANDER_TO_PLAYER); } //have chance, //RageFromHurt >50 //rage max = 100.as //hurt run away time min and max } else if (_awayFromTarget == AWAY_MODE.AWAY_AFTER_ATTACK) { //have chance to hit again //or run away if (ret < _chanceToAwayAfterAttack) { SetNextSeekMode(SEEK_MODE.RUN_AWAY_AFTER_ATTACK); } else { GoToAttack(); } } else { // FC_DANGER_LEVEL dl = GetTargetDangerLevel(3, 8); if (dl == FC_DANGER_LEVEL.SAFE) { _hesitateJitter = Random.Range(_hesitateJitterMin, _hesitateJitterMax); SetNextSeekMode(SEEK_MODE.WANDER_TO_PLAYER); } else if (dl == FC_DANGER_LEVEL.DANGER) { SetNextSeekMode(SEEK_MODE.RUN_AWAY_AFTER_ATTACK); //SetNextSeekMode(SEEK_MODE.RUN_AWAY_AFTER_ATTACK); } else { SetNextSeekMode(SEEK_MODE.RUN_AWAY_AFTER_HURT); } } if (_usedForFly) { _owner.MoveFollowForward = true; _owner.CurrentAngleSpeed = _angleSpeedForFlyWander; } ChangeToSeekMode(); } else if (cmd == FCCommand.CMD.STATE_UPDATE) { UpdateHesitate(); } else if (cmd == FCCommand.CMD.STATE_QUIT) { StopAllCoroutines(); _owner.CurrentAngleSpeed = _owner.Data.angleSpeed; _owner.ACAniSpeedRecoverToNormal(); _owner.ACRestoreToDefaultSpeed(); _owner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); //_owner.MoveFollowForward = false; } }
public void UpdateAnimation() { //11 l //12 r //13 f //14 b Vector3 d1 = _owner.ThisTransform.forward; float angle = Vector3.Angle(_owner.MoveDirection, d1); if (_targetAC.MoveDirection == Vector3.zero && _currentSeekMode == SEEK_MODE.COPY_PLAYER && _owner.MoveDirection == Vector3.zero) { if (_aniSwitch._aniIdx != FC_All_ANI_ENUM.idle) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.idle; _owner.ACPlayAnimation(_aniSwitch); _owner.ACAniSpeedRecoverToNormal(); _hDirection = HES_DIRECTION.NONE; } } else if (_currentSeekMode == SEEK_MODE.COPY_PLAYER || _currentSeekMode == SEEK_MODE.RUN_AWAY_AFTER_ATTACK || _currentSeekMode == SEEK_MODE.WANDER_TO_PLAYER || _currentSeekMode == SEEK_MODE.WANDER_BY_SIMPLE_PATH) { if (angle > 165) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleB1; if (_hDirection != HES_DIRECTION.BACK) { _hDirection = HES_DIRECTION.BACK; _owner.ACPlayAnimation(_aniSwitch); } } else if (angle < 15) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleF1; if (_hDirection != HES_DIRECTION.FORWARD) { _hDirection = HES_DIRECTION.FORWARD; _owner.ACPlayAnimation(_aniSwitch); } } else { d1.Normalize(); float zz = d1.z * _owner.MoveDirection.x - d1.x * _owner.MoveDirection.z; if (zz < 0) { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleR1; if (_hDirection != HES_DIRECTION.RIGHT) { _hDirection = HES_DIRECTION.RIGHT; _owner.ACPlayAnimation(_aniSwitch); } } else { _aniSwitch._aniIdx = FC_All_ANI_ENUM.runCircleL1; if (_hDirection != HES_DIRECTION.LEFT) { _hDirection = HES_DIRECTION.LEFT; _owner.ACPlayAnimation(_aniSwitch); } } } } }
private IEnumerator WANDER_AROUND_PLAYER() { _owner.ACOwner.ACSetMoveMode(MoveAgent.MOVE_MODE.BY_MOVE_MANUAL); _owner.ACOwner.CurrentAngleSpeed = _wanderAngleSpeed; _hDirection = HES_DIRECTION.NONE; _inState = true; if (_usedForFly) { _owner.ACOwner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.FOLLOW_SPEED); } else { _owner.ACOwner.SetShipForSpeedAndForward(MoveAgent.ROTATE_FLAG.UNLOCK); } float timeCount = 0.001f; float timeCount1 = _wanderTime; if (_wanderTimeOverride <= 0) { _wanderTimeOverride = _wanderTime; } timeCount1 = _wanderTimeOverride; float timeCount2 = 0.001f; while (_inState) { timeCount1 -= Time.deltaTime; if (timeCount1 <= 0) { _inState = false; } if (timeCount > 0) { timeCount -= Time.deltaTime; if (timeCount <= 0) { Vector3 v3 = _owner.TargetAC.ThisTransform.localPosition - _owner.ACOwner.ThisTransform.localPosition; v3.y = 0; float lenSqrt = v3.sqrMagnitude; v3.Normalize(); Vector3 wd = GetWanderDirection(lenSqrt, ref v3); _owner.MoveByDirection(wd, _wanderSpeed, _wanderTimeOverride + 1f, true); timeCount = _timeToRefreshWander; timeCount2 = 0.001f; } } if (timeCount2 > 0) { timeCount2 -= Time.deltaTime; if (timeCount2 <= 0) { UpdateFaceTarget(); timeCount2 = _timeToRefreshFace; } } UpdateAnimation(); yield return(null); } _owner.ACOwner.ACSetMoveMode(MoveAgent.MOVE_MODE.BY_ANIMATION); _owner.ACOwner.ACRevertToDefalutMoveParams(); _hDirection = HES_DIRECTION.NONE; if (_SpActionIsEnd != null) { _SpActionIsEnd(FC_SP_ACTION_LISTS.RUN_RANDOM, FC_SP_ACTION_CONDITONS.AFTER_IDLE); } }