Arrow Project
Summary
Inspired by Yondu's arrow in Guardians of the Galaxy, I decided to try turning it into a game mechanic. The player has to mark targets individually and then the arrow will fly between them.
Video
Breakdown Summary
The concept of the arrow projectile is as follows.
1) When the player holds the throw command (right click in this case), they enter a "mark targets" state. While in this state, raycasts are fired looking for objects tagged as "target".
2) Whenever a valid target is detected, it is added to an array after ensuring that it's not already in that array.
3) When the player releases the right click, a projectile is launched out and the projectile homes in to the first target in the array.
4) After striking a target, it gets the next target in the array and homes in on it. This is repeated until there are no targets remaining.
5) When there are no more targets, the arrow sets the player as the homing target and returns.
1) When the player holds the throw command (right click in this case), they enter a "mark targets" state. While in this state, raycasts are fired looking for objects tagged as "target".
2) Whenever a valid target is detected, it is added to an array after ensuring that it's not already in that array.
3) When the player releases the right click, a projectile is launched out and the projectile homes in to the first target in the array.
4) After striking a target, it gets the next target in the array and homes in on it. This is repeated until there are no targets remaining.
5) When there are no more targets, the arrow sets the player as the homing target and returns.
Sort of tutorial (it's a little chaotic because some things happen simultaneously but I tried to go in a logical fashion)
I started with the UE4 first person shooter template and then modified it from there. I made the animations and FX but won't be going into those here.
PLAYER BLUEPRINT
1) When the player holds the throw command (right click in this case), they enter a "mark targets" state. While in this state, raycasts are fired looking for objects tagged as "target".
3) When the player releases the right click, a projectile is launched out and the projectile homes in to the first target in the array.
3) When the player releases the right click, a projectile is launched out and the projectile homes in to the first target in the array.
Right mouse button is used for input.
-When it's pressed, the character first checks if the arrow is already flying and prevents anything from happening if it is so there's not multiple arrows flying around.
-Then a variable called "arrowMarkTargets" is set to true. This tells the character to start checking for targets.
-For visual feedback, it plays an animation, sets the game to slomo, and zooms in as well as adding a vignette.
-Once the button is released, visual effects are reverted.
-The "arrowMarkTargets" boolean is set to false to stop checking. If there are targets marked, then the fire arrow animation is played.
-If there are no targets marked, the character goes back to normal.
-When it's pressed, the character first checks if the arrow is already flying and prevents anything from happening if it is so there's not multiple arrows flying around.
-Then a variable called "arrowMarkTargets" is set to true. This tells the character to start checking for targets.
-For visual feedback, it plays an animation, sets the game to slomo, and zooms in as well as adding a vignette.
-Once the button is released, visual effects are reverted.
-The "arrowMarkTargets" boolean is set to false to stop checking. If there are targets marked, then the fire arrow animation is played.
-If there are no targets marked, the character goes back to normal.
-The throwing animation fires a notify from the animation blueprint that casts to the character blueprint calling function "fireArrow". This function spawns the projectile, passing the array of targets and materials to it.
(instead of using an animation notify, one can directly call the "fireArrow" function at the part where the fire arrow animation is played to avoid the use of animation.)
(instead of using an animation notify, one can directly call the "fireArrow" function at the part where the fire arrow animation is played to avoid the use of animation.)
2) Whenever a valid target is detected, it is added to an array after ensuring that it's not already in that array.
-Every frame, it checks if the player is in the mark target state (if "arrowMarkTargets" is true)
-If so, fire a sphere trace looking for objects with collision type "target"
-When it detects one, add it to the array of targets if it's not already in it. Also save the material that the object has so it can be restored.
-Set the material to glow for visual feedback
-If so, fire a sphere trace looking for objects with collision type "target"
-When it detects one, add it to the array of targets if it's not already in it. Also save the material that the object has so it can be restored.
-Set the material to glow for visual feedback
PROJECTILE BLUEPRINT
3) When the player releases the right click, a projectile is launched out and the projectile homes in to the first target in the array.
4) After striking a target, it gets the next target in the array and homes in on it. This is repeated until there are no targets remaining.
5) When there are no more targets, the arrow sets the player as the homing target and returns.
4) After striking a target, it gets the next target in the array and homes in on it. This is repeated until there are no targets remaining.
5) When there are no more targets, the arrow sets the player as the homing target and returns.
-When the projectile is spawned, it first makes sure it's a homing projectile and then calls "setNewTarget"
-The first index in the array is set as the homing target component of the projectile and then the index is incremented for later.
-The first index in the array is set as the homing target component of the projectile and then the index is incremented for later.
-When the projectile collides with an object, it checks if it's the intended target. If not, then it simply passes through it.
-If the object hit is the intended target, then the projectile applies damage and sets the material back to normal. This part can be replaced with whatever the programmer/designer wants. I won't go into how to use the "Apply Point Damage" node here since they can be found online.
-After it applies damage, the projectile checks if there are targets remaining, which is based on comparing the length of the array of targets to the current index of the array. If there are still targets to hit, then the projectile sets the next array item as the next target and repeats step 1 once it hits it. During this part, I added some randomizers to change speed and whatnot to make the projectile more visually interesting, but it can simply call "setNewTarget" again.
-If there are no more targets, then the homing target is set to the player and the "return" boolean is set to true. Once the projectile hits the player, the projectile calls the "arrowReturned" function in the player blueprint and then destroys itself.
-If the object hit is the intended target, then the projectile applies damage and sets the material back to normal. This part can be replaced with whatever the programmer/designer wants. I won't go into how to use the "Apply Point Damage" node here since they can be found online.
-After it applies damage, the projectile checks if there are targets remaining, which is based on comparing the length of the array of targets to the current index of the array. If there are still targets to hit, then the projectile sets the next array item as the next target and repeats step 1 once it hits it. During this part, I added some randomizers to change speed and whatnot to make the projectile more visually interesting, but it can simply call "setNewTarget" again.
-If there are no more targets, then the homing target is set to the player and the "return" boolean is set to true. Once the projectile hits the player, the projectile calls the "arrowReturned" function in the player blueprint and then destroys itself.
PLAYER BLUEPRINT
-When the projectile calls the "arrowReturned" function, the character blueprint plays the catching animation and sets the "arrowFlying" boolean to false so that the player can mark new targets and throw more arrows like a pro.