Forum begins after the advertisement:


[Part 4] Change other animation for the Up Spell

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 4] Change other animation for the Up Spell

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12131
    Level 12
    Participant
    Helpful?
    Up
    0
    ::

    Thank you for your awesome videos, but i have one question:
    In your video, you use same the animation for 3 spell, but i want to change the animation for the Up spell. So how can i do that?
    Can you guide me detail please? I study graphic design but my school forced me to code the game myself for homework so this is my first time coding.
    Thank you very much and sorry for bothering you

    #12132
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    Hi Vĩ,

    You need to add an additional parameter, like so:

    IEnumerator CastCoroutine()
        {
            anim.SetBool("Casting", true);
            
            yield return new WaitForSeconds(0.15f);
    
            //side cast
            if (yAxis == 0 || (yAxis < 0 && Grounded()))
            {
                GameObject _fireBall = Instantiate(sideSpellFireball, SideAttackTransform.position, Quaternion.identity);
    
                //flip fireball
                if(pState.lookingRight)
                {
                    _fireBall.transform.eulerAngles = Vector3.zero; // if facing right, fireball continues as per normal
                }
                else
                {
                    _fireBall.transform.eulerAngles = new Vector2(_fireBall.transform.eulerAngles.x, 180); 
                    //if not facing right, rotate the fireball 180 deg
                }
                pState.recoilingX = true;
                anim.SetInteger("Direction", 1);
            }
    
            //up cast
            else if( yAxis > 0)
            {
                anim.SetInteger("Direction", 0);
                Instantiate(upSpellExplosion, transform);
                rb.velocity = Vector2.zero;
            }
    
            //down cast
            else if(yAxis < 0 && !Grounded())
            {
                downSpellFireball.SetActive(true);
            }
    
            Mana -= manaSpellCost;
            yield return new WaitForSeconds(0.35f);
            anim.SetBool("Casting", false);
            pState.casting = false;
        }

    Then, add an extra spell animation state on the Animator, and set your transitions to both spell states as such:

    1. One of them will trigger when Casting is true and Direction equals 0
    2. The other will trigger when Casting is true and Direction equals 1

    I make Direction an integer instead of a boolean so that if you want to add more animation variants in future. You can do it.

    Hope this is clear!

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: