예제 #1
0
    // Same as animation,
    // [Header("Hit FX Impact")]
    // public SO_ImpactFX sOImpactFX;
    // private ImpactFX impactFX;
    // public ImpactFXPool impactFXPool;
    // private Vector3 hitPosition;

    public IEnumerator TakeHitAnimation()
    {
        // Hit FX.
        //HitEffect();
        // Slow down time.
        TimeSlow.StartTimeSlow(0.25f);
        // Set camera nudge backwards from the hit.
        CameraFollow.CameraNudge_St(normHitDirection, takeHitCamNudge);
        //StartCoroutine(TimeSlow.SlowTimeScale(5, 0));
        // Can be transfered to the update.
        // Switch this for an Interumpt/Stun, stop all input, attacks, etc. Can also add variables for knockback and stun duration, based on damage received, buffs, damage immunity, etc.
        // Player cannot move with input.
        charMov.StopInputMove();
        // Player cannot flip.
        charMov.charCanFlip = false;
        charMov.FlipSpriteDirectionBased(normHitDirection);
        // Stops; player attack movement, attack FXs that are stopped on stun, weapon attack motion. When stopping attack with true, player will be interupted but will immediately be able to start a new attack.
        charAtk.StopAttack(true);
        // Player weapon does not follow cursor.
        weapLookAt.lookAtEnabled = false;
        //
        // Setup hit animation.
        timer          = 0f;
        spriteNumber   = 0;
        spriteR.sprite = hitSprites[0];
        spriteNumber++;
        while (timer < getHitDuration)
        {
            //print("Should be changing sprite to getting hit in the face sprite.");
            timer += Time.deltaTime /* /getHitDuration */;
            if (spriteNumber < hitSprites.Length && timer > hitSpriteTimings[spriteNumber])
            {
                spriteR.sprite = hitSprites[spriteNumber];
                spriteNumber++;
            }
            yield return(null);
        }
        // If health reaches 0, iniate death sequence.
        if (currentHealth <= 0f)
        {
            charDeath.CharacterDies();
        }
        else
        {
            charMov.canInputMove = true;
            //charAtk.atkChain.ready = true;
            weapLookAt.lookAtEnabled = true;
            charMov.charCanFlip      = true;
        }
    }
 public override void SetupNextMotion()
 {
     curMotion++;
     curHoldMotion = false;
     if (curMotion < holdMotions.Length - 1 && holdMotions[curMotion])
     {
         curHoldMotion = true;
     }
     else
     {
         curHoldMotion = false;
     }
     // At what motion can the player start his next attack and swap his weapon.
     // if (curMotion >= sOWeaponMotionStab.allowAttackAndSwap) {
     //     charAtk.ReadyToAttack(true);
     //charAtk.readyToAtk = true;
     //charAtk.atkChain.ready = true;
     //     charAtk.equippedWeapons.canSwapWeapon = true;
     // }
     // At what motion will the camera nudge.
     if (curMotion >= sOWeaponMotionStab.nudgeCamera && !camNudged)
     {
         CameraFollow.CameraNudge_St((charAtk.moIn.mousePosWorld2D - (Vector2)charAtk.transform.position).normalized, sOWeaponMotionStab.nudgeDistance);
         camNudged = true;
     }
     // If there are no more attack motions.
     if (curMotion >= motionDurations.Length)
     {
         weapMotionOn = false;
         resetWeapRot = true;
         curYPos      = endYPos;
         startYPos    = curYPos;
         endYPos      = restingY;
         moveTimer    = 0f;
         //charAtk.readyToAtk = true;
         //charAtk.atkChain.ready = true;
         // Setup weapon reset here.
         return;
     }
     curMotionDur = motionDurations[curMotion];
     curYPos      = endYPos;
     startYPos    = curYPos;
     endYPos      = yPositions[curMotion];
     curAnimCurve = animCurves[curMotion];
     moveTimer    = 0f;
 }
예제 #3
0
 public override void SetupNextMotion()
 {
     curMotion++;
     // At what motion can the player start his next attack and swap his weapon.
     // if (curMotion >= sOWeaponMotionSlash.allowAttackAndSwap) {
     // charAtk.ReadyToAttack(true);
     // charAtk.equippedWeapons.canSwapWeapon = true;
     // }
     // At what motion will the camera nudge.
     if (curMotion >= sOWeaponMotionSlash.nudgeCamera && !camNudged)
     {
         CameraFollow.CameraNudge_St((charAtk.moIn.mousePosWorld2D - (Vector2)charAtk.transform.position).normalized, sOWeaponMotionSlash.nudgeDistance);
         camNudged = true;
     }
     // If there are no more attack motions.
     if (curMotion == motionDurations.Length)
     {
         StopAllCoroutines();
         if (!dontReset)
         {
             StartCoroutine(ResetWeapon());
         }
         //weapMotionOn = false;
         resetWeapOn = true;
         curRot      = endRot;
         startRot    = curRot;
         endRot      = restingRotation * -1;
         moveTimer   = 0f;
         // charAtk.readyToAtk = true;
         // charAtk.atkChain.ready = true;
         // Setup weapon reset here.
         return;
     }
     // Setup the next weapon motion values.
     curMotionDur = motionDurations[curMotion];
     curRot       = endRot;
     startRot     = curRot;
     endRot       = rotations[curMotion];
     curAnimCurve = animCurves[curMotion];
     moveTimer    = 0f;
     StopAllCoroutines();
     StartCoroutine(WeaponMotionOn());
 }
예제 #4
0
 public void StartTakeHit()
 {
     // Slow down time.
     TimeSlow.StartTimeSlow(0.25f);
     // Set camera nudge backwards from the hit.
     CameraFollow.CameraNudge_St(normHitDirection, takeHitCamNudge);
     charMov.StopInputMove(false, false);
     // Player cannot flip.
     charMov.charCanFlip = false;
     charMov.FlipSpriteDirectionBased(normHitDirection);
     // Stops; player attack movement, attack FXs that are stopped on stun, weapon attack motion.
     //charAtk.StopAttack();
     // Stop the player from attacking while they are in the TakeHit animation.
     //charAtk.atkChain.ready = false;
     //charAtk.ReadyToAttack(false);
     // Player weapon does not follow cursor.
     weapLookAt.lookAtEnabled = false;
     // Start the player getting hit animation.
     charMov.mySpriteAnim.Play(clipHit);
 }
예제 #5
0
    // public PolygonCollider2D[] attackColliders;
    // public bool[] activeAttacks;
    // public PolygonCollider2D attackCollider;
    // public List<Collider2D> collidersHit;
    // public List<Collider2D> collidersDamaged;

    public IEnumerator AttackCollider(bool attackFromWeaponOne, SO_Weapon sOWeapon, SO_Weapon.AttackChain WeapAtkChain, SO_AttackFX sO_AttackFX, PolygonCollider2D atkFXCol, Transform weapOrigTrans)
    {
        // References from the SO_AttackFX.
        float thisColStart = sO_AttackFX.colStart;
        float thisColEnd   = sO_AttackFX.colEnd;

        // Set chosen pool attack FX collider off in case the attack FX dosn't use a collider.
        atkFXCol.enabled = false;
        SO_ImpactFX sO_ImpactFX = sO_AttackFX.soImpactFX;

        // Apply the collision shape and offset position to the chosen pool collider.
        atkFXCol.points = sO_AttackFX.collider.points;
        atkFXCol.offset = sO_AttackFX.collider.offset;
        // Set other variables.
        List <Collider2D> collidersHit     = new List <Collider2D>();
        List <Collider2D> collidersDamaged = new List <Collider2D>();
        float             timer            = 0f;
        bool detectCol  = false;
        bool hitAnEnemy = false;

        // Wait a frame to avoid having the collider appear for a frame at its last position, the atkFX's new position HAS to be set before the collider is enabled. (Maybe specifically for atkFX's that have the same colStart time, first sprite time and moveDelay all set to the same value)
        yield return(null);

        while (timer < thisColEnd)
        {
            timer += Time.deltaTime;
            if (timer >= thisColStart && !detectCol)
            {
                yield return(null);

                // If the attack has a collider, enable it otherwise leave it off.
                if (sO_AttackFX.collider)
                {
                    atkFXCol.enabled = true;
                }
                detectCol = true;
                yield return(null);
            }
            if (detectCol)
            {
                // Detect hit collision.
                Physics2D.OverlapCollider(atkFXCol, hitLayers, collidersHit);
                foreach (Collider2D col in collidersHit)
                {
                    if (!collidersDamaged.Contains(col))
                    {
                        collidersDamaged.Add(col);
                        // If this is an enemy, apply damage.
                        if (col.gameObject.CompareTag("Enemy"))
                        {
                            col.GetComponent <Enemy_Health>().ReceiveDamage(WeapAtkChain.DamageRoll, charEquippedWeapons.activeWeapon.poiseDamage, atkFXCol.transform.position, col.bounds.center);
                            // If at least one enemy is hit apply durability damage to the active weapon.
                            if (!hitAnEnemy)
                            {
                                hitAnEnemy = true;
                                if (sOWeapon.durabilityDamageOnHit)
                                {
                                    charEquippedWeapons.DurabilityDamage(attackFromWeaponOne);
                                }
                            }
                        }
                        else if (col.gameObject.CompareTag("Destructible"))
                        {
                            col.GetComponent <Clutter_Health>().ReceiveDamage(WeapAtkChain.DamageRoll, atkFXCol.transform.position, col.bounds.center);
                        }
                        // Hit impact FX. Apply the correct rotation, position, sprites and layerMask to an impactFX.
                        HitImpact.PlayImpactFX(atkFXCol, col.bounds.center, sO_ImpactFX, hitLayers.layerMask, col);
                        // Set camera nudge backwards from the hit.
                        CameraFollow.CameraNudge_St(weapOrigTrans.up, nudgeStrength);
                        // Slow time. Duration to be set by weapon damage, slow to be adjusted (animation curve) by TimeSlow script.
                        TimeSlow.StartTimeSlow(timeSlowDur);
                        //Debug.Log("Collider: " + col.gameObject.name + " was hit! Hit hit, hurraay!");
                    }
                }
            }
            yield return(null);
        }
        if (collidersHit.Count > 0)
        {
            collidersHit.Clear();
            collidersDamaged.Clear();
        }
        atkFXCol.enabled = false;
        yield return(null);
    }