Tech Blog 2 - Orchestrating Visual Effects
·Another important topic that had to be nailed down is how do we orchestrate “everything visual” that is associated with a specific event in the game?
For example, imagine character A attacking character B using card C. On an abstract level, this action can be as simple as:
B(hit points) - A(damage)
Easy right? Indeed.
Now when we face the fact that there must be visuals related to the event of A attacking B, things get complicated really quickly even for this simple case.
Initially before having animations in place, I added DOTween Pro to do at least “something” instead of a static screen. Lets see how the case above looks like implemented with DOTween Pro.
public class CardMb
{
public void ActivateOn(CharacterMb target)
{
// Animate cards text to fade out colour
cardTexts.ForEach(t =>
{
t.DOColor(Color.clear, 0.3f);
});
// Animate card sprite renderers text to fade out colour
cardSpriteRenderers.ForEach(sr =>
{
sr.DOColor(Color.clear, 0.3f);
});
// Animate card to increase in size
gameObject.transform.DOScale(new Vector3(1.25f, 1.25f, 0), 0.3f);
// Animate character that issued attack
sourceCharacter.transform.DOLocalMoveX(1, 0.1f)
.OnComplete(() =>
{
sourceCharacter.transform.DOLocalMoveX(0, 0.1f);
});
// Animate character that received attack
target.transform.DOLocalMoveX(0.5f, 0.1f)
.OnComplete(() =>
{
target.transform.DOLocalMoveX(0, 0.1f);
});
}
}
Result:
Of course the code above can be refactored but the real problem for me will remain. “What, when and how” everything happens is described in the code and I don't want that. I want to decouple all that ideally so that in the code everything is as simple as on an abstract level, and all that complexity can be managed through the Editor.
DOTween Pro doesn’t provide that solution obviously, it’s just a tweening library and does it really well. I had in mind long time ago one library that might be doing exactly what i want. It’s called FEEL.
FEEL turned out to do things exactly how I see they should work. I do still have technical issues here and there, but I believe it’s mostly me NOT knowing features that do exist. FEEL is also extensible, well documented and code is easy to understand. Definitely better than writing something from scratch.
Code above now can be re-written to this:
public class CardMb
{
public void ActivateOn()
{
useCardFeedback.PlayFeedback();
sourceCharacterAttackFeedback.PlayFeedback();
targetCharacterReceiveDamageFeedback.PlayFeedback();
}
}
Easy right? Complexity though has not vanished, it just moved to a separate place, which is in the Editor:
Abstracting this to the editor seems to be correct to me. More importantly where staff like previewing animations & effects can be iterated separately from actually running the game, which will undoubtedly increase iteration speed.