top of page

MFP: Directional Targeting & Projectiles

Unmissable point and click abilities are all well and good, but they tend to lack skill-expression and so can't be made too powerful. Aimed abilities on the other hand can be made stronger un order to reward the player for successfully hitting their target. There are a few different types of aimed abilities, often referred to as skillshots. The first I have implemented is a directionally targeted projectile, meaning an ability which spawns in an object which travels a set distance towards the mouse cursor.

I began by adding an else if statement to the actiavte ability function in the base ability script which calls a new "direction" function if the ability's targeting mode is set to "direction".









I then created the direction function which call a different directional function based if the parent character is a player or enemy.








In the player direction function we raycast to the ground at the mouse position, stop moving and turn our character to face that point before calling to complete direction function to finish the ability.

On the other hand, enemies will check if they are in range to hit their target first. If they are in range then they stop and turn to face them just like the player does. If not, then they will move into range and then do so.

Once they are in range and facing their target, they call the complete direction function due to this addition made to the update function in the enemy controller script:

The complete direction function behaves similarly to the create effect function explained in a previous post. First we check if this is a projectile ability. This is done because there may be different ability types later which use the directional targeting system. If this is a projectile type ability, the function instantiates a projectile prefab from the resources folder with a specific position and rotation and a scale increasing with the character's bonus area stat. All the relevant variables such as speed, range and damage are modified based on the ability's base values and the character's stats. The projectile is also notified which character and ability created it. Another new option exclusive to projectile abilities is the piercing bool. If set to true, the projectile will pass through characters, hitting multiple targets, otherwise it will stop at the first character hit, affecting only them. Once all this information is passed from the ability to the projectile, the ready to fire function in the projectile is called. This will be used to inform the projectile that it has all the necessary info and may begin traveling towards its destination. The ability is then placed on cooldown.

Now that we have all the code to spawn and set up our projectile, we should probably make a projectile to spawn. To do this I created a sphere object in the scene, set its collider to be a trigger and gave it a rigidbody with the rotations locked and gravity turned off. I then created a projectile script and added that to the sphere object too. I then dragged the sphere into the resources folder, making it a prefab, before deleting the sphere from the scene. I also created a new florescent yellow material and placed it on the sphere prefab just to make it stand out.

To give the projectiles a position to fire from I also added a empty child object to the player and enemy characters called front fire point.

I then added a simple find game object line in the player and enemy controller scripts so that they have a reference to the fire point.

So now we have a projectile and a method for spawning it. Time get into the projectile script and give it some functionality. First I declared all of the variables which will be set by the spawning ability.






We then add a range check to the update function which calls a self destruction function once the projectile reaches max range.

Next we have our ready to fire function which is called by the creating ability once all the projectile's variables are set. This gets a reference to the ridigbody so we can move, saves our starting position for the range check, and then fires the projectile forwards.





An on trigger enter function applies damage and effects to any opponents hit and then calls destroy self after the first if the projectile is not piercing.

Lastly we have our destroy self function which does exactly that when called by the range or collision check.




Here is a quick demo video of all of this working in-game:


Σχόλια


bottom of page