public void RecibeMonsterState(StatePosition _state, bool _isAttack, bool _moveAble, Vector3 _movePoint, GameObject _Player) { if (_state == StatePosition.Run) { movePoint = _movePoint; monsterState = _state; } if (_state == StatePosition.Attack) { monsterState = _state; } if (_state == StatePosition.TakeDamage) { monsterState = _state; } if (_state == StatePosition.Idle) { monsterState = _state; } if (_state == StatePosition.Death) { monsterState = _state; } monsterState = _state; isAttack = _isAttack; moveAble = _moveAble; Pattern(monsterState); if (_Player != null) { targetPlayer = _Player; } }
public void HitDamage(int _Damage, GameObject _weapon) { // currentHP -= _Damage; if (currentHP > 0) { for (int i = 0; i < player.Length; i++) { if (player [i] == _weapon) { playerToMonsterDamage [i] += _Damage; } } statePosition = StatePosition.TakeDamage; Pattern(statePosition); } else { currentHP = 0; IsAlive = false; HittedBox.enabled = false; statePosition = StatePosition.Death; Pattern(statePosition); } }
// initialize a new state private State(StatePosition position) { Position = position; ParameterIndex = 0; ParameterNavigatorDepth = 0; ParameterAttributeIndex = 0; }
// initialize a clone state private State(State other, bool recurse = false) { Position = other.Position; _content = other._content; SiblingIndex = other.SiblingIndex; Siblings = other.Siblings; FieldsCount = other.FieldsCount; FieldIndex = other.FieldIndex; if (Position == StatePosition.PropertyXml) { XmlFragmentNavigator = other.XmlFragmentNavigator.Clone(); } // NielsK did //Parent = other.Parent; // but that creates corrupted stacks of states when cloning // because clones share the parents : have to clone the whole // stack of states. Avoid recursion. if (recurse) { return; } var clone = this; while (other.Parent != null) { clone.Parent = new State(other.Parent, true); clone = clone.Parent; other = other.Parent; } }
IEnumerator MiddleBossSkillAI() { roarBreak = true; aniState = this.animator.GetCurrentAnimatorStateInfo(0); while (IsAlive) { yield return(new WaitForSeconds(10f)); bossRandomPattern = Random.Range(0, 1); // pattern = 1; bossSkill = true; animator.SetBool("BossSkill", true); checkDirection = targetPlayer.transform.position - transform.position; if (checkDirection.z > 0) { movePoint = new Vector3(checkDirection.x, 0, checkDirection.z - 3f); } if (checkDirection.z < 0) { movePoint = new Vector3(checkDirection.x, 0, checkDirection.z + 3f); } bossRandomPattern = 0; statePosition = StatePosition.BossOneHandAttack; Pattern(statePosition); yield return(new WaitForSeconds(1.0f)); bossSkill = false; animator.SetBool("BossSkill", false); } }
public void OnAirborne() { if (RB.velocity.y < 0) { return; } State_Position = StatePosition.Airborne; }
public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { animator.SetInteger("State", 0); break; } case StatePosition.Attack: { AttackProcess(isAttack); break; } case StatePosition.Run: { if (!aniState.IsName("Attack")) { AnimatorReset(); } animator.SetInteger("State", 1); break; } case StatePosition.TakeDamage: { animator.SetTrigger("TakeDamage"); break; } case StatePosition.Death: { animator.SetTrigger("Death"); //MonsterArrayEraser(this.gameObject); break; } case StatePosition.BossOneHandAttack: { animator.SetInteger("State", 3); break; } case StatePosition.BossJumpAttack: { animator.SetInteger("State", 4); break; } } }
// initialize a clone state private State(State other) { Position = other.Position; ParameterIndex = other.ParameterIndex; if (Position == StatePosition.ParameterNavigator) { ParameterNavigator = other.ParameterNavigator.Clone(); ParameterNavigatorDepth = other.ParameterNavigatorDepth; ParameterAttributeIndex = other.ParameterAttributeIndex; } }
public void OnLanded(Collider2D landedOn) { if (RB.velocity.y > 0) { return; } JumpsRemaining = MaxJumps; JumpCooldownRemaining = 0f; AirdashesRemaining = MaxAirdash; State_Position = StatePosition.Grounded; //set position to flat on the platform var y = landedOn.transform.position.y + landedOn.transform.localScale.y / 2f + transform.localScale.y / 2f; transform.position = new Vector3(transform.position.x, y, transform.position.z); }
//name change -> MonsterNormalActAI; public IEnumerator PatternNormalChange() { while (IsAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; if (Mathf.Abs(targetPlayer.transform.position.z - transform.position.z) < 8 && Mathf.Abs(targetPlayer.transform.position.x - this.gameObject.transform.position.x) <= 0.6f) { if (!isAttack) { isAttack = true; moveAble = false; } monsterState = StatePosition.Attack; if (checkDirection.z > 0) { LookAtPattern(right); } if (checkDirection.z < 0) { LookAtPattern(left); } Pattern(monsterState); yield return(new WaitForSeconds(0.5f)); } else if (currentDisTance > searchRange) { moveAble = false; isAttack = false; monsterState = StatePosition.Idle; Pattern(monsterState); } else { moveAble = true; isAttack = false; monsterState = StatePosition.Run; Pattern(monsterState); } } yield return(new WaitForSeconds(0.2f)); } }
// public IEnumerator pointVectorchange() // { // while (true) // { // for (int i = 0; i < pointVector.Length; i++) // { // if (i > 0 && i < pointVector.Length - 1) // { // transitionVector = pointVector[i]; // pointVector[i] = pointVector[i + 1]; // pointVector[i + 1] = transitionVector; // } // // if (i == pointVector.Length - 1) // { // transitionVector = pointVector[i]; // pointVector[i] = pointVector[0]; // pointVector[0] = transitionVector; // } // } // yield return new WaitForSeconds(0.5f); // } // } //animation Set; move; public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { this.transform.Translate(idlePoint * Time.deltaTime, 0); animator.SetInteger("State", 0); break; } case StatePosition.Boom: { idlePoint = this.gameObject.transform.position; IsAlive = false; StartCoroutine("BoomCoroutine"); break; } // animator boom -> setintter 4 case StatePosition.Attack: { AttackProcess(isAttack); break; } case StatePosition.Run: { AnimatorReset(); animator.SetInteger("State", 2); break; } case StatePosition.TakeDamage: { animator.SetTrigger("TakeDamage"); break; } case StatePosition.Death: { animator.SetTrigger("Death"); // MonsterArrayEraser(this.gameObject); break; } } }
public IEnumerator PatternNormalChange() { while (IsAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; if (currentDisTance > searchRange) { monsterState = StatePosition.Idle; Pattern(monsterState); SendMonsterState(monsterState, isAttack, moveAble, movePoint, targetPlayer); } //if this object get Attackmotion pattern(stateposition.boom -> attack), and this monsterlife is 20%, boomPattern start; else if (currentDisTance <= searchRange) { // movePoint = new Vector3(checkDirection.x,0,checkDirection.z); { if (currentDisTance > searchRange * 0.2f) { moveAble = true; isAttack = false; monsterState = StatePosition.Run; Pattern(monsterState); SendMonsterState(monsterState, isAttack, moveAble, movePoint, targetPlayer); } if (currentDisTance <= searchRange * 0.3f) { if (!isAttack) { isAttack = true; moveAble = false; } monsterState = StatePosition.Attack; Pattern(monsterState); yield return(new WaitForSeconds(0.5f)); } } } } yield return(new WaitForSeconds(0.2f)); } }
// //animation Set; move; public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { this.transform.Translate(idlePoint * Time.deltaTime, 0); // animator.SetInteger("State", 0); break; } case StatePosition.Boom: { idlePoint = this.gameObject.transform.position; StartCoroutine("BoomCoroutine"); break; } // animator boom -> setintter 4 case StatePosition.Attack: { StartCoroutine(AttackProcess()); break; } case StatePosition.Run: { AnimatorReset(); this.transform.Translate(movePoint * moveSpeed * Time.deltaTime, 0); // animator.SetInteger("State", 2); searchRange = 10; break; } case StatePosition.TakeDamage: { StartCoroutine(TakeDamageCorutine()); break; } case StatePosition.Death: { MonsterArrayEraser(this.gameObject); break; } } }
IEnumerator BossSkillAI() { aniState = this.animator.GetCurrentAnimatorStateInfo(0); bossRandomPattern = 0; while (IsAlive) { yield return(new WaitForSeconds(10f)); bossSkill = true; animator.SetBool("BossSkill", true); if (bossRandomPattern == 0) { statePosition = StatePosition.BossJumpAttack; Pattern(statePosition); } else if (bossRandomPattern == 1) { if (!roarBreak) { roarBreak = true; statePosition = StatePosition.BossOneHandAttack; Pattern(statePosition); } } else if (bossRandomPattern == 2) { statePosition = StatePosition.BossRoar; Pattern(statePosition); } yield return(new WaitForSeconds(1.0f)); bossRandomPattern++; if (bossRandomPattern > 1) { bossRandomPattern = 0; } bossSkill = false; animator.SetBool("BossSkill", false); } }
//animation Set; move; public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { this.transform.Translate(idlePoint, 0); break; } case StatePosition.Attack: { this.transform.Translate(attackPoint, 0); break; } case StatePosition.Run: { this.transform.Translate(movePoint * moveSpeed * Time.deltaTime, 0); break; } case StatePosition.Death: { this.gameObject.SetActive(false); break; } } }
//animation Set; move; public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { this.transform.Translate(idlePoint * Time.deltaTime, 0); animator.SetInteger("State", 0); break; } case StatePosition.Attack: { AttackProcess(isAttack); break; } case StatePosition.Run: { AnimatorReset(); animator.SetInteger("State", 2); //searchRange = 10; break; } case StatePosition.TakeDamage: { animator.SetTrigger("TakeDamage"); break; } case StatePosition.Death: { animator.SetTrigger("Death"); //MonsterArrayEraser(this.gameObject); break; } } }
public void HitDamage(int _Damage) { currentHP -= _Damage; Debug.Log("in boss"); if (currentHP > 0) { if (monsterId != MonsterId.Bear || monsterId != MonsterId.BlackBear) { statePosition = StatePosition.TakeDamage; Pattern(statePosition); } } else { currentHP = 0; // IsAlive = false; HittedBox.enabled = false; statePosition = StatePosition.Death; Pattern(statePosition); Destroy(this.gameObject, 3f); } }
// initialize a clone state private State(State other, bool recurse = false) { Position = other.Position; _content = other._content; SiblingIndex = other.SiblingIndex; Siblings = other.Siblings; FieldsCount = other.FieldsCount; FieldIndex = other.FieldIndex; if (Position == StatePosition.PropertyXml) XmlFragmentNavigator = other.XmlFragmentNavigator.Clone(); // NielsK did //Parent = other.Parent; // but that creates corrupted stacks of states when cloning // because clones share the parents : have to clone the whole // stack of states. Avoid recursion. if (recurse) return; var clone = this; while (other.Parent != null) { clone.Parent = new State(other.Parent, true); clone = clone.Parent; other = other.Parent; } }
// server code; public void SendMonsterState(StatePosition _state, bool _isAttack, bool _moveAble, Vector3 _movePoint, GameObject _Player) { //send to server; }
IEnumerator MonsterActAI(bool _normal) { while (_normal) { if (isAlive) { yield return(new WaitForSeconds(0.2f)); if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; if (currentDisTance > searchRange) { statePosition = StatePosition.Idle; Pattern(statePosition); } else if (currentDisTance <= searchRange) { { if (currentDisTance > attackRange) { moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } if (currentDisTance <= attackRange) { if (!isAttack) { isAttack = true; moveAble = false; } statePosition = StatePosition.Attack; Pattern(statePosition); yield return(new WaitForSeconds(0.5f)); } } } } } while (!_normal) { if (isAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; } attackCycle += 0.2f; //int int randomvariable = Random.Range(1, 4); if (attackCycle > randomvariable) { statePosition = StatePosition.Idle; Pattern(statePosition); yield return(new WaitForSeconds(0.5f)); moveAble = false; isAttack = true; statePosition = StatePosition.Attack; Pattern(statePosition); yield return(new WaitForSeconds(1.0f)); attackCycle = 0; } if (attackCycle <= randomvariable) { moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } yield return(new WaitForSeconds(0.2f)); } } } }
IEnumerator BossActAI() { while (true) { if (isAlive) { if (!bossSkill) { aniState = this.animator.GetCurrentAnimatorStateInfo(0); if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, transform.position); checkDirection = targetPlayer.transform.position - transform.position; if (!aniState.IsName("Attack")) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, transform.position); checkDirection = targetPlayer.transform.position - transform.position; if (checkDirection.z > 0) { LookAtPattern(right); } if (checkDirection.z < 0) { LookAtPattern(left); } } if (currentDisTance < attackRange && bossNormalAttackCycle) { statePosition = StatePosition.Attack; bossNormalAttackCycle = false; Pattern(statePosition); yield return(new WaitForSeconds(1)); } if (currentDisTance > searchRange) { statePosition = StatePosition.Idle; Pattern(statePosition); if (aniState.IsName("Idle")) { //changedirection } } else if (currentDisTance <= searchRange && currentDisTance > attackRange && moveAble) { statePosition = StatePosition.Run; Pattern(statePosition); movePoint = checkDirection; } if (aniState.IsName("Attack")) { for (int i = 0; i < attackCollider.Length; i++) { attackCollider [i].enabled = true; } } else if (aniState.IsName("Attack")) { for (int i = 0; i < attackCollider.Length; i++) { attackCollider [i].enabled = false; } } } } yield return(new WaitForSeconds(0.2f)); } if (!isAlive) { break; } } }
// initialize a new state // used for creating the very first state // and also when moving to a child element public State(INavigableContent content, State parent, IList <int> siblings, int siblingIndex, StatePosition position) : this(position) { Content = content; Parent = parent; Depth = parent?.Depth + 1 ?? 0; Siblings = siblings; SiblingIndex = siblingIndex; }
IEnumerator BossActAI() { while (isAlive) { if (!bossSkill) { aniState = this.animator.GetCurrentAnimatorStateInfo(0); if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, transform.position); checkDirection = targetPlayer.transform.position - transform.position; if (!aniState.IsName("Attack")) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, transform.position); checkDirection = targetPlayer.transform.position - transform.position; } if (currentDisTance < attackRange && bossNormalAttackCycle) { statePosition = StatePosition.Attack; bossNormalAttackCycle = false; Pattern(statePosition); yield return(new WaitForSeconds(1)); } if (currentDisTance > searchRange) { statePosition = StatePosition.Idle; Pattern(statePosition); if (aniState.IsName("Idle")) { BosschangeDirection(); } } else if (currentDisTance <= searchRange && currentDisTance > attackRange && moveAble) { statePosition = StatePosition.Run; Pattern(statePosition); movePoint = checkDirection; if (aniState.IsName("Run")) { BosschangeDirection(); transform.Translate((targetPlayer.transform.position - transform.position) * moveSpeed * Time.deltaTime, 0);//반대로 걸어 가서 수정 } } if (aniState.IsName("Attack")) { for (int i = 0; i < attackCollider.Length; i++) { attackCollider[i].enabled = true; } } else if (aniState.IsName("Attack")) { for (int i = 0; i < attackCollider.Length; i++) { attackCollider[i].enabled = false; } } } } yield return(new WaitForSeconds(0.2f)); } }
// initialize a new state private State(StatePosition position) { Position = position; FieldIndex = -1; }
IEnumerator MonsterActAI(bool _normal) { while (_normal) { if (isAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; if (currentDisTance > searchRange) { statePosition = StatePosition.Idle; Pattern(statePosition); } //if this object get Attackmotion pattern(stateposition.boom -> attack), and this monsterlife is 20%, boomPattern start; else if (currentDisTance <= searchRange) { { if (currentDisTance > searchRange * 0.2f) { moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } if (currentDisTance <= searchRange * 0.3f) { if (!isAttack) { isAttack = true; moveAble = false; } statePosition = StatePosition.Attack; Pattern(statePosition); if (checkDirection.z > 0) { LookAtPattern(right); } if (checkDirection.z < 0) { LookAtPattern(left); } yield return(new WaitForSeconds(0.5f)); } } } } yield return(new WaitForSeconds(0.2f)); } else { break; } } while (!_normal) { if (isAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; } attackCycle += 0.2f; //int if (attackCycle > 3) { statePosition = StatePosition.Idle; Pattern(statePosition); yield return(new WaitForSeconds(1.3f)); if (checkDirection.z > 0) { LookAtPattern(right); } if (checkDirection.z <= 0) { LookAtPattern(left); } moveAble = false; isAttack = true; statePosition = StatePosition.Attack; Pattern(statePosition); yield return(new WaitForSeconds(2f)); attackCycle = 0; } if (attackCycle <= 3) { LookAtPattern(left); moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } yield return(new WaitForSeconds(0.2f)); } else { break; } } }
// initialize a new state // used for creating the very first state // and also when moving to a child element public State(INavigableContent content, State parent, IList<int> siblings, int siblingIndex, StatePosition position) : this(position) { Content = content; Parent = parent; Siblings = siblings; SiblingIndex = siblingIndex; }
// initialize a new state private State(StatePosition position) { Position = position; FieldIndex = -1; }
// initialize a clone state private State(State other) { Position = other.Position; ParameterIndex = other.ParameterIndex; if (Position == StatePosition.ParameterNavigator) { ParameterNavigator = other.ParameterNavigator.Clone(); ParameterNavigatorDepth = other.ParameterNavigatorDepth; ParameterAttributeIndex = other.ParameterAttributeIndex; } }
// initialize a new state private State(StatePosition position) { Position = position; ParameterIndex = 0; ParameterNavigatorDepth = 0; ParameterAttributeIndex = 0; }
public void Pattern(StatePosition state) { switch (state) { case StatePosition.Idle: { if (!aniState.IsName("Idle")) { animator.SetInteger("State", 0); } break; } case StatePosition.Attack: { AttackProcess(isAttack); break; } case StatePosition.Run: { animator.SetInteger("State", 1); break; } case StatePosition.TakeDamage: { animator.SetTrigger("TakeDamage"); break; } case StatePosition.Death: { animator.SetTrigger("Death"); //MonsterArrayEraser(this.gameObject); break; } case StatePosition.BossOneHandAttack: { animator.SetInteger("State", 3); break; } case StatePosition.BossJumpAttack: { animator.SetInteger("State", 4); break; } case StatePosition.BossRoar: { animator.SetInteger("State", 5); break; } } if (NetworkManager.Instance.MyIndex == 0) { DataSender.Instance.MonsterStateSend((byte)state, monsterIndex); } }
IEnumerator MonsterActAIADC(bool _normalMode) { while (_normalMode) { if (isAlive) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; if (Mathf.Abs(targetPlayer.transform.position.z - transform.position.z) < attackRange && Mathf.Abs(targetPlayer.transform.position.x - this.gameObject.transform.position.x) <= 1.5f) { if (!isAttack) { isAttack = true; moveAble = false; } statePosition = StatePosition.Attack; Pattern(statePosition); yield return(new WaitForSeconds(0.5f)); } else if (currentDisTance > searchRange) { moveAble = false; isAttack = false; statePosition = StatePosition.Idle; Pattern(statePosition); } else { moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } } yield return(new WaitForSeconds(0.2f)); } else { yield return(new WaitForSeconds(0.2f)); } } while (!_normalMode) { if (targetPlayer != null) { currentDisTance = Vector3.Distance(targetPlayer.transform.position, this.gameObject.transform.position); checkDirection = targetPlayer.transform.position - this.gameObject.transform.position; } attackCycle += 0.2f; int randomvariable = Random.Range(1, 4); if (attackCycle > 1 + randomvariable) { statePosition = StatePosition.Idle; Pattern(statePosition); yield return(new WaitForSeconds(1.3f)); moveAble = false; isAttack = true; statePosition = StatePosition.Attack; Pattern(statePosition); yield return(new WaitForSeconds(2f)); attackCycle = 0; } if (attackCycle <= 1 + randomvariable) { LookAtPattern(right); moveAble = true; isAttack = false; statePosition = StatePosition.Run; Pattern(statePosition); } yield return(new WaitForSeconds(0.2f)); } }