Can this course's Enemy scripts be used for multiple types of enemies?

I wanted to know how best to construct multiple types of enemies (with different behaviors), like a melee Grunt, a ranged Archer, a parrying Knight, a jumping Assassin, etc.

Would It be best to make those four+ enemy types share the course’s Enemy scripts, or would it be preferable to give them each their own type of enemy script, like GruntBaseState, ArcherStateMachine, etc?

I believe you’d be able to reuse the state machine, but the states would be different. They may share a lot of states, but a parrying Knight will not have the same Jump state as a jumping Assassin. You may need to derive specific classes off the base enemy state machine

States like EnemyIdleState and EnemyChaseState can easily be shared between the enemies. What you’ll need is a way to disambiguate which states a Melee, or ranged character would need to use… This could be as simple as adding some bools to the EnemyStateMachine, or as complicated as using a WeaponConfig like in the RPG course… Here’s sort of what I would do in the former case (I’m actually prototyping the latter case right now for a future tutorial on mixing the RPG course and this course).

In EnemyStateMachine

[field: SerializeField] public bool IsRanged {get; private set;}
[field: SerializeField] public bool CanParry {get; private set;}
[field: SerializeField] public bool CanLeapAttack {get; private set;}

The easiest example here is in the IsRanged case… in EnemyChaseState, if the target (player) is in range,

if(stateMachine.IsRanged)
{
    stateMachine.SwitchState(new EnemyRangedAttack(stateMachine));
} else
{
    stateMachine.SwitchState(new EnemyMeleeAttack(stateMachine));
}
1 Like

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

Privacy & Terms