Get 25% off your next order from the Unity Asset Store: YW86GYBU8S.
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
- This topic has 1 reply, 2 voices, and was last updated 2 years ago by
Terence.
-
AuthorPosts
-
October 29, 2023 at 8:15 pm #12131::
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
October 29, 2023 at 10:20 pm #12132::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:
- One of them will trigger when Casting is true and Direction equals 0
- 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!
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: