top of page

MFP: Single Target Attacks

Both player characters and enemies function using the same set of core systems. This means that when implementing a feature for the player, it also has to be usable by the enemies. This, along with the fact that everything must by made modular to ensure it can be properly generated by algorithms, makes the addition of each system quite challenging and time consuming. This is acceptable, as making the systems in this way, will save time in the long run and they can be used by the algorithms to generate lots of content for us.

Our player is now able to move around, take damage and die. Next we need to give them some abilities to fight with. I added series of empty ability game objects attached to the player and created a base ability script which I added to each of them. I then declared and assigned the objects and scripts in the base character script.







I then added an activate ability function to the base ability script which, depending on the ability's targeting type string, will call the function to target the ability.







For the player, each ability is attached to a button. Pressing that button calls the activate ability function in the corresponding ability.














When creating ability functionality, I began with the simplest possible version, point and click single target damage. The damage system and the raycasting used for movement were already implemented so this was a logical starting point. Before any targeting could occur, we need to know who is using the ability so we can determine who they can target.







From here the player and enemy require different targeting functions as the player will be using their mouse input but the enemy will, of course, not.

This function detects if the player is pointing their mouse at an enemy when the ability is active and applies the abilities effects to them if they are in range.

If the ability used is a damaging ability, it will then deal damage scaling with the user's power to their target. "What happens if they're out of range!" I hear you cry. Well, we could have opted for a simple out of range message, but that would make the gameplay feel a bit clunky. Other games in the genre cause the player to run into range in this situation, so since I would have to do something similar for the enemies anyway, that is what I did. In the targeting function I added an else statement for if the player is out of range.

I then created a move into range function sets the enemy as the player's target so they can track their location and sets the ability in question as their "casting ability" so that the player script knows what to do once in range. We then calculate the closest in-range position the player can move to and set it as our nav agent destination, causing the player to run into range and then activate the ability.

Over in the player controller, I then wrote a check into the update function which causes the "casting ability" to go off once in-range.

I then added a couple of lines to the apply effect function so that when the ability goes off, the player turns to face their target, and a new cooldown function is called, stopping the player using the ability again for a short time.

This function is a coroutine, meaning I can pause it. This allows me to put the ability on cooldown for a set amount of time, then take it back off cooldown again with one function.

Here is all this in action on a dummy enemy:



コメント


bottom of page