Exemplo n.º 1
0
    IEnumerator Attack()
    {
        currentState       = State.Attacking;
        pathFinder.enabled = false;

        Vector3 originalPosition = transform.position;
        Vector3 dirToTarget      = (target.position - transform.position).normalized;
        Vector3 attackPosition   = target.position - dirToTarget * (myCollisionRadius);

        float attackSpeed = 3;
        float percent     = 0;

        skinMaterial.color = Color.red;
        bool hasAppliedDamage = false;

        while (percent <= 1)
        {
            if (percent >= .5f && !hasAppliedDamage)
            {
                hasAppliedDamage = true;
                targetEntity.TakeDamage(damage);
            }

            percent += Time.deltaTime * attackSpeed;
            float interpolation = (-Mathf.Pow(percent, 2) + percent) * 4;
            transform.position = Vector3.Lerp(originalPosition, attackPosition, interpolation);

            yield return(null);
        }

        skinMaterial.color = originalColor;
        currentState       = State.Chasing;
        pathFinder.enabled = true;
    }
Exemplo n.º 2
0
 public override void ProcessNodeHit(Player player, LiveEntity target, RaycastHit2D collision)
 {
     if (!target.invincible)
     {
         target.TakeDamage(player.Stats["damage"] / 2);
         Transform t         = target.attachedObject.transform;
         Vector2   knockback = (-collision.normal + player.hookVelocity).normalized / 2 * player.hookKnockback * Mathf.Clamp(player.hookVelocity.magnitude, 1, 2) * player.hookMass;
         //Vector2 knockback = collision.normal * -hookKnockback;
         target.ApplyKnockback(knockback, 0.15f, 0.03f, 0.1f);
     }
 }
Exemplo n.º 3
0
    IEnumerator Attack()
    {
        Material material      = GetComponent <Renderer>().material;
        Color    originalColor = material.color;

        state = State.Attacking;
        pathFinder.enabled = false;

        Vector3 originalPosition  = transform.position;
        Vector3 directionToTarget = (target.position - transform.position).normalized;
        Vector3 attackPosition    = target.position - directionToTarget * collisionRadius;

        const float attackSpeed      = 3.0f;
        float       percentCompleted = 0.0f;

        material.color = Color.red;
        bool hasAppliedDamage = false;

        while (percentCompleted <= 1)
        {
            if (percentCompleted > 0.5f && !hasAppliedDamage)
            {
                hasAppliedDamage = true;
                targetEntity.TakeDamage(attackDamage);
            }

            percentCompleted += Time.deltaTime * attackSpeed;
            // `interpolation` is a point on a porabola. Since the enemy will lunge forward and then
            // receed, we need to increase a value gradually from zero and then decrease it back to zero.
            // This is expressable as the equation `y = 4(-x^2 + x)`.
            float interpolation = (-Mathf.Pow(percentCompleted, 2) + percentCompleted) * 4;
            transform.position = Vector3.Lerp(originalPosition, attackPosition, interpolation);

            yield return(null);
        }

        material.color     = originalColor;
        state              = State.Chasing;
        pathFinder.enabled = true;
    }