public void UpdateState() { hasLineOfSight = enemy.CheckLineOfSight(rangedAttackBuffer); if (!hasLineOfSight) { enemy.chase.EnterState(); return; } //Special attack if (enemy.hasSpecialAttack && enemy.specialAttackAvailable && (enemy.target.position - enemy.transform.position).magnitude >= enemy.minSpecialAttackRange) { if (RollRandom.RollForProbability(enemy.specialAttackProbability)) { //Debug.Log("SPECIAL"); enemy.special.EnterState(); return; } else { enemy.StartSpecialCooldown(); } } //Melee attack else if (enemy.hasMeleeAttack && enemy.navMeshAgent.hasPath && enemy.navMeshAgent.remainingDistance < enemy.navMeshAgent.stoppingDistance) { //Debug.Log("MELEE"); enemy.melee.EnterState(); } //Continue chasing else//if (enemy.navMeshAgent.hasPath && (enemy.target.position - enemy.transform.position).magnitude >= enemy.navMeshAgent.stoppingDistance) { //Debug.Log("CHASING"); enemy.chase.EnterState(); return; } /*if (enemy.grounded && enemy.navMeshAgent.hasPath && enemy.navMeshAgent.remainingDistance <= enemy.minSpecialAttackRange) * { * Debug.Log("CHASING"); * enemy.chase.EnterState(); * return; * }*/ }
public void UpdateState() { //TODO Add a raycast to check for line of sight before the enemy can stop to make a ranged attack. if no line of sight the enemy must keep moving closer hasLineOfSight = enemy.CheckLineOfSight(0); if (enemy.hasSpecialAttack && hasLineOfSight && enemy.grounded && enemy.specialAttackAvailable && (enemy.target.position - enemy.transform.position).magnitude >= enemy.minSpecialAttackRange) // && enemy.navMeshAgent.remainingDistance >= enemy.minSpecialAttackRange && enemy.navMeshAgent.remainingDistance <= enemy.maxSpecialAttackRange) { //Debug.Log("SPECIAL ATTACK"); enemy.attack.EnterState(); return; } if (enemy.hasMeleeAttack && enemy.navMeshAgent.hasPath && enemy.grounded && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && enemy.navMeshAgent.velocity.magnitude <= 0) { //Debug.Log("DESTINATION REACHED"); enemy.attack.EnterState(); return; } }
public void UpdateState() { if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable) { /*enemy.specialFrontSwing = false; * enemy.specialSwing = false; * enemy.specialBackSwing = false;*/ enemy.specialAttackStart = false; enemy.specialAttackEnd = false; attacking = true; projectileLaunched = false; } /*if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance) //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer * { * enemy.chase.EnterState(); * }*/ if (attacking) { timer += Time.deltaTime; if (timer <= frontSwing) //Front swing of the attack animation { /*if (!enemy.specialFrontSwing) * enemy.specialFrontSwing = true;*/ if (!enemy.specialAttackStart) { enemy.specialAttackStart = true; } //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow; //Debug.Log("FRONT SWING"); } else if (timer >= frontSwing && timer < frontSwing + attackTime) //Beginning of the attack after front swing. Performs attack { /*enemy.specialFrontSwing = false; * if (!enemy.specialSwing) * enemy.specialSwing = true;*/ enemy.specialAttacking = true; //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red; if (!projectileLaunched) { Vector3 temp = new Vector3(enemy.transform.position.x, enemy.transform.position.y + enemy.transform.lossyScale.y, enemy.transform.position.z); Vector3 tempPos = new Vector3(enemy.transform.position.x, enemy.transform.position.y + (enemy.transform.lossyScale.y * 0.5f), enemy.transform.position.z) + enemy.transform.forward * 0.5f; GameObject rangedProjectile = enemy.ShootProjectile(enemy.target.GetChild(0).position - tempPos, projectileSpeed); rangedProjectile.GetComponent <EnemyProjectile>().knockback = enemy.specialKnockback; projectileLaunched = true; } //Debug.Log("ATTACK"); } else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing) //Back swing of the animation { enemy.specialRecovering = true; enemy.specialAttackStart = false; /*enemy.specialSwing = false; * if (!enemy.specialBackSwing) * enemy.specialBackSwing = true;*/ //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue; //Debug.Log("BACK SWING"); } else if (timer >= frontSwing + attackTime + backSwing) //End of attack animation. { //enemy.specialBackSwing = false; enemy.specialAttackEnd = true; enemy.specialAttacking = false; enemy.specialRecovering = false; //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray; //Debug.Log("END ATTACK"); enemy.StartSpecialCooldown(); if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance) { enemy.special.EnterState(); } else { enemy.chase.EnterState(); } } } else { Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position); enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed); if (!enemy.CheckLineOfSight(rangedAttackBuffer)) { enemy.chase.EnterState(); } } }
public void UpdateState() { if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.meleeAttackAvailable) { /*enemy.meleeFrontSwing = false; * enemy.meleeSwing = false; * enemy.meleeBackSwing = false;*/ enemy.meleeAttackStart = false; enemy.meleeAttackEnd = false; attacking = true; damageDealt = false; } if (!attacking && enemy.navMeshAgent.remainingDistance >= enemy.navMeshAgent.stoppingDistance) //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer { enemy.chase.EnterState(); } if (attacking) { timer += Time.deltaTime; if (timer <= frontSwing) //Front swing of the attack animation { /*if (!enemy.meleeFrontSwing) * enemy.meleeFrontSwing = true;*/ if (!enemy.meleeAttackStart) { enemy.meleeAttackStart = true; } if (enemy.IndicatorTemp) { enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.yellow; } //Debug.Log("FRONT SWING"); } else if (timer >= frontSwing && timer < frontSwing + attackTime) //Beginning of the attack after front swing. Performs attack { /*enemy.meleeFrontSwing = false; * if (!enemy.meleeSwing) * enemy.meleeSwing = true;*/ if (enemy.IndicatorTemp) { enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.red; } //Debug.Log("PERFORM ATTACK"); if (!damageDealt) { MeleeCollision(enemy.transform.position + enemy.transform.forward, 1); } } else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing) //Back swing of the animation { /*enemy.meleeSwing = false; * if (!enemy.meleeBackSwing) * enemy.meleeBackSwing = true;*/ enemy.meleeAttacking = true; enemy.MeleeRecovering = true; enemy.meleeAttackStart = false; if (enemy.IndicatorTemp) { enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.blue; } //Debug.Log("BACK SWING"); } else if (timer >= frontSwing + attackTime + backSwing) //End of attack animation. { //enemy.meleeBackSwing = false; enemy.meleeAttackEnd = true; enemy.meleeAttacking = false; enemy.MeleeRecovering = false; if (enemy.IndicatorTemp) { enemy.IndicatorTemp.GetComponent <Renderer>().material.color = Color.gray; } //Debug.Log("END ATTACK"); enemy.StartMeleeCooldown(); enemy.chase.EnterState(); } } else { Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position); enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed); if (!enemy.CheckLineOfSight(rangedAttackBuffer)) { enemy.chase.EnterState(); } } }
public void UpdateState() { if (!attacking && enemy.FaceTargetCheck(rangedAttackBuffer) && enemy.specialAttackAvailable) { /*enemy.specialFrontSwing = false; * enemy.specialSwing = false; * enemy.specialBackSwing = false;*/ enemy.specialAttackStart = false; enemy.specialAttackEnd = false; attacking = true; lungeDir = enemy.transform.forward; damageDealt = false; } if (!attacking && enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance) //Maybe not needed. depends how stiff we want the AI to be. remove if needs to be stiffer { enemy.chase.EnterState(); } if (attacking) { timer += Time.deltaTime; if (timer <= frontSwing) //Front swing of the attack animation { /*if (!enemy.specialFrontSwing) * enemy.specialFrontSwing = true;*/ if (!enemy.specialAttackStart) { enemy.specialAttackStart = true; } //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.yellow; } else if (timer >= frontSwing && timer < frontSwing + attackTime) //Beginning of the attack after front swing. Performs attack { /*enemy.specialFrontSwing = false; * if (!enemy.specialSwing) * enemy.specialSwing = true;*/ //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.red; if (!enemy.GetComponent <Rigidbody>()) { enemy.gameObject.AddComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation; } enemy.navMeshAgent.enabled = false; enemy.lunging = true; enemy.GetComponent <Rigidbody>().velocity = lungeDir * Time.deltaTime * lungeSpeed; } else if (timer >= frontSwing + attackTime && timer < frontSwing + attackTime + backSwing) //Back swing of the animation { /*enemy.specialSwing = false; * if (!enemy.specialBackSwing) * enemy.specialBackSwing = true;*/ enemy.specialAttacking = true; enemy.specialRecovering = true; enemy.specialAttackStart = false; //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.blue; enemy.navMeshAgent.enabled = true; enemy.lunging = false; //Debug.Log("BACK SWING"); } else if (timer >= frontSwing + attackTime + backSwing) //End of attack animation. { //enemy.specialBackSwing = false; enemy.specialAttackEnd = true; enemy.specialAttacking = false; enemy.specialRecovering = false; //if (enemy.IndicatorTemp) //enemy.IndicatorTemp.GetComponent<Renderer>().material.color = Color.gray; //Debug.Log("END ATTACK"); enemy.StartSpecialCooldown(); if (RollRandom.RollForProbability(enemy.specialAttackContinueProbability) && enemy.navMeshAgent.remainingDistance > enemy.navMeshAgent.stoppingDistance) { enemy.special.EnterState(); } else { enemy.chase.EnterState(); } } } else { enemy.lunging = false; Quaternion rotation = Quaternion.LookRotation(new Vector3(enemy.target.position.x, enemy.transform.position.y, enemy.target.position.z) - enemy.transform.position); enemy.transform.rotation = Quaternion.Slerp(enemy.transform.rotation, rotation, Time.deltaTime * turnSpeed); if (!enemy.CheckLineOfSight(rangedAttackBuffer)) { enemy.chase.EnterState(); } } }