Shooting Animations Added

This commit is contained in:
2022-02-25 23:36:20 +03:00
parent 3b8cee973f
commit f338283adb
13 changed files with 532 additions and 2 deletions

View File

@@ -20,6 +20,8 @@ namespace AI
protected Transform target = null;
protected bool isShooting = false;
protected IMovement movement = null;
protected Animator animator = null;
protected int layerMask = ~(1 << 9);
protected bool canShoot => target != null && (target.transform.position - transform.position).sqrMagnitude < attackRangeSquared;
@@ -41,6 +43,7 @@ namespace AI
protected virtual void Start()
{
movement = transform.GetComponentInParent<IMovement>();
animator = transform.GetComponentInParent<Animator>();
UpdateTarget(FindObjectOfType<Player.PlayerController>()?.transform);
}
@@ -57,8 +60,11 @@ namespace AI
isShooting = true;
float movementBaseSpeed = movement.BaseSpeed;
movement.BaseSpeed = 0f;
animator.SetBool("isAttacking", true);
animator.speed = 0f;
yield return new WaitForSeconds(focusingTime);
animator.speed = 1f;
while (canShoot)
{
@@ -67,6 +73,7 @@ namespace AI
yield return null;
}
movement.BaseSpeed = movementBaseSpeed;
animator.SetBool("isAttacking", false);
isShooting = false;
}
@@ -77,7 +84,7 @@ namespace AI
Vector3 velocity = GetVelocityForProjectile(timeForProjectileToHit);
RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, target.position - transform.position, attackRange);
RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, target.position - transform.position, attackRange, layerMask);
if (raycastHit2D.transform != target)
velocity = GetVelocityForProjectile(timeForProjectileToHit * 2);