How to know which ability?

I understood how the strategy pattern works and why we’re using interfaces, but my question is, in the AbilityRunner script, how we would fire the rage ability method rather than the heal or fireball methods, or other cases?

Thanks!

The course example is rather abstract, and doesn’t much get into the actual weeds of selection…

In my own case, I’m working on a State Machine that uses ScriptableObjects to represent the states. In this case, the StateMachine itself has fields to assign things like a NonCombat state, a Combat state, an Attack state, a special attack state, etc

[field: SerializeField] public ScriptableState NonCombatState {get; private set;}  //Idle?  Patrol?
[field: SerializeField] public ScriptableState CombatState {get; private set;} //Chase?  Sound Alarm?  Teleport?
[field: SerializeField] public ScriptableState AttackState {get; private set;} // Slash?  Punch? 
[field: SerializeField] public ScriptableState CastingState {get; private set;} //Heal?  Fireball?  Rage?

Then in the inspector for each character, you set the appropriate ScriptableState for that category. At runtime, if the player is in pursuit range, you call the CombatState, if not, the NonCombatState, and if the player is in attack range, you call the AttackState. I’m probably going to be using some sort of condition to determine if the assigned CastingState is appropriate to call. So a Fireball state might require a target in range and Mana. A Heal state might require that the character has been damaged, and the Rage ability might require that somebody has made Dr. Banner very angry .

1 Like

Love it!
Of course applying these design patterns in real projects is way better, so I would like to know which courses that you recommend.

Thanks!

For state machines in general, I strongly recommend our Third Person Combat and Traversal course. Nathan does a deep dive into State Machines, and one of the most comprehensive looks at using the new InputSystem through code that I’ve seen to date.

For many of the other patterns, I strongly recommend our RPG series courses, especially Shops and Abilities as it does a deep dive into the Strategy Pattern (which you may notice what I described in my previous message is a combination of a State Pattern and a Strategy Pattern, stealing ideas from both of these courses).

* Note: I am the TA in both the Third Person course and the RPG series, so it’s possible I’m biased.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms