// Kunne måske laves i en ekstern klasse så man kan skifte attack? private IEnumerator Attack() { currentState = State.Attacking; pathfinder.enabled = false; Vector3 originalPosition = transform.position; Vector3 targetPosition = target.transform.position; float attackSpeed = 3; float percent = 0; bool hasAppliedDamage = false; while (percent <= 1) { float heightDifToTarget = targetPosition.y - transform.position.y; if (percent >= .5f && !hasAppliedDamage && heightDifToTarget < .5f) { hasAppliedDamage = true; target.Damage(damage); } percent += Time.deltaTime * attackSpeed; float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4; transform.position = Vector3.Lerp(originalPosition, targetPosition, interpolation); yield return(null); } currentState = State.Chasing; pathfinder.enabled = true; }
private void Shoot() { RaycastHit hit; if (_livingEntity && (!NavMeshAgent.hasPath && Vector3.Distance(transform.position, TargetTransform.position) <= MeleeDamage || NavMeshAgent.remainingDistance <= MeleeDistance)) { _livingEntity.Damage(MeleeDamage); } else if (_gunProjectileSpawn && NavMeshAgent.remainingDistance <= AttackDistance && Vector3.Angle(TargetTransform.position - _headTransform.position, _headTransform.forward) <= FoV && Physics.Linecast(_headTransform.position, TargetTransform.position, out hit) && hit.transform == TargetTransform) { _gunProjectileSpawn.Fire(); } }