Posted May 02, 2022 by Arcane Studios
Continuing with the player’s animation system, I was tasked with designing our spell system this week. In this discussion I’ll be describing how I implemented responding to user input for spell casting and how I tied that together with the animation state machine.
Spells in Mythicism work as follows: Every spell the player has comes two ways of using it: with a Quick Spell (a projectile) and with a Trap Spell (a placeable). The quick spells and trap spells are meant to go hand in hand with each other. For example, with a Fire Spell, the Quick Spell would be a fireball and the Trap Spell would be a burning circle that enemies can step into. So there would need to be two different animations for casting spells. Easy enough.
The problem I faced was that we wanted to bind both the quick spell and the trap spell to the same key. When the player tapped the F key, the quick spell should play, and when they held the F key, the trap spell should play. We also needed to set it up so that if the player let go of the F key too soon, the trap spell would be canceled. In Unreal, I only had two input events to work with on the player side: key Pressed and key Released.
The solution I came up with was fairly simple but quite effective. First, for needing to hold down the trap spell in order to pace it, that was simple. I added an Animation Trigger for beginning to place a trap spell, and another for stopping, and called them on Pressed and Released respectively.
The animation state machine was then set up to transition out of the animation when the key was released.
What about the quick spell?
Well that was simple too. I put a check on the player blueprint for when the F key was Released to see if a small enough amount of time had passed. If the elapsed time was small enough, I would trigger a Quick Spell animation instead.
Then in the animation blueprint, I set it up so that the beginning of the Trap Spell animation would seamlessly transition into the Quick Spell animation. And that was how I went about handling user input for spell casting in our game.
Author: Reilly da Silva