Attack action

Hi,

I’ve implemented attacking in my game but was wondering how you guys go about making a character in your platform game
run and attack the player?

I do it two ways - I use raycast from the bad guy to the player, if they can see them, they head towards them and then start attacking them,
other way is, if player is in close proximity they attack that way. I do all this via a simple state machine.

Thanks