AI has a hard time targeting jumping enemies

All my npcs have a real hard time calculating the path I assume when an enemy is jumping, or when an enemy is on a higher Y axis than them. No idea on how I can prevent this. Any ideas?

Old code:

State: 0: If (Enemy is visible) { State: 1 }

State 1: If (Enemy is visible) { Move to enemy, set state to 2 } Else { Set state to 0 }

State 2: If (Enemy is visible) { Move to enemy } Else { Set state to 0 }

New code:

State: 0: If (Enemy is visible) { State: 1 }

State 1: If (Enemy is visible) { If (Enemy is on the same Y axis) { Move to enemy, set state to 2 } Else { Jump, set state to 2 } } Else { Set state to 0 }

State 2: If (Enemy is visible) { Move to enemy } Else { Set state to 0 }

Enemies don’t have a set state?

Because I’m creating my enemies from the top down, I’m finding it hard to set a next state for my enemies. I’m not entirely sure how I can set a state for them.

Any ideas?

Old code:

State: 0: If (Player is visible) { State: 1 }

State 1: If (Player is visible) { Move to player, set state to 2 } Else { Set state to 0 }

State 2: If (Player is visible) { Move to player } Else { Set state to 0 }

How would I make the AI attack based on how far the player is?

I want to make it so the enemy will attack the player when the player is within a certain distance. I’m not really sure how I would do this. I’m thinking I would use the DistanceTo function, but I’m not entirely sure how I would do that.

Old code:

State: 0: If (Player is visible) { State: 1 }

State 1: If (Player is visible) { Move to player, set state to 2 } Else { Set state to 0 }

State 2: If (Player is visible) { Move to player } Else { Set state to 0 }

New code:

State: 0: If (Player is visible) { State: 1 }

State 1: