Introduction to Projectiles
Chapter 1 – Introduction
Howdy people and welcome to my second DBZ themed tutorial in Indie Game Maker. This time I’ll be focusing on how to properly set up and use projectiles. Projectiles are anything that can be thrown, launched, shot, etc. They can be bullets, boomerangs, arrows, rocks, grenades, missiles, also magic spells like fireballs, or in this case, KI based attacks like the normal KI blast shown in Figure 1.1.
Figure 1.1 – Example of a projectile.
Like in my last tutorial, I’m not going to teach you how to set up a map, or make a player gadget. Such tutorials can be found here and here, respectively.
Also as far as resources go, you can use your own, but for the tutorials sake, I’ll provide you with some resources.
Spoiler
Also, this tutorial also covers the other types of collision boxes. So if you want to get a feel for them, check out my tutorial on how to Properly set up Collision Boxes.
Chapter 2 – Setting up the Character Animation
On a quick side note, if you aren’t using the Goku and have your own sprite sheet, you can skip this section, as it just goes through the gadget collision box, and also setting the linkage points. Arighty, once we have the resources in the game and set up, we need to make the animations. In your hero’s Animation, create 3 new actions. Name them Ki_Blast_01/02/03 respectively, and assign the appropriate poses for each facing, which are the first, second and third columns of the 11th, 12th, 13th and 14th of the Goku sprite sheet (or just refer to Figure 2.1, if you’re confused).
Figure 2.1 – The Frames we’re going to use.
Each facing of each action only needs 1 frame, so there is no actual animation. Next we need to switch on the Collision Detection button, so we can see what we’re doing. Now to reiterate, our collision boxes determine the collision between certain objects.
Figure 2.2 - Collision Detection button
The Blue box is for gadget interactions, collisions etc. I recommend you set it to a slighty larger size than the green box, because this collision box also handles your hit detection, and if something hits your character and it’s blue box is the same as it’s green box, then the actual gadget that’s hitting it will have trouble trying to determine whether it hit a wall or your character. This is unproven and is just a theory by me.
The Green box, as discussed in my last tutorial is for detecting whether the gadget has collided with a wall (a tile with the red markers around it).
The Red box handles hitting, so if Goku performs a punch, then the red box would be around his arm, or fist, so that the Maker can determine hits towards enemy gadgets or towards you. If this box touches or is in the blue box, the maker registers a hit and acts accordingly as set by the player.
Figure 2.3 – An example of all the boxes in action.
Okay, onto Linkage points. A Linkage point is an object which other objects can be attached to or launched from. For example, if the player has a sword as a separate animation/gadget, he can set a junction point on his player to determine where his sword comes from when he starts-a-swingin’. Setting a junction point is crucial to this tutorial, so we need to set one up. Since Goku’s KI blast will be launched from his hands on the second and third KI blast animations, we only have to focus on those actions, because the first action is just a dramatic pull back pose.
To set linkage points, there are 2 ways to do so. The first way is to click on the little green squares and drag them to a position you feel good with. The second way is to scroll down to the bottom of the Display Settings area to a section called “Linkage Point,” you can use those to place your junction point. Place your junction point to about the middle area of his hand for all facings on both actions (KI_Blast_01/02). You only need to use junction number 1 for everything.
Figure 2.4 – Example of where to place the Linkage Point.
Chapter 3 – Setting up the Projectile Animation
Create a new animation and call it KI blast or something along those lines. This animation will have 3 actions, called Fire, Exploded, and gone. Before you set up the animations, in the Per-Frame Settings tab, there’s a section called Display Settings, the first option there is called “Offset”. Set all of your frames to an offset of -50x and -50y, this puts your sprite frame in the middle of the red cross. We do this because when the actual gadget is launched from the player, the sprite will appear in the middle of the hand, instead of a few pixels below it. Set up the fire animations and all the collision boxes, remembering to make the wall collision detection smaller than the gadget collision detection. You don’t need to worry about Linkage Points.
Figure 3.1 – Example of the Projectile.
The Exploded animation is just 1 frame long, it’s sprite is the purple explosion thing and it doesn’t need any collision boxes. The same applies with the Gone animation, since it is the animation in which the gadget destroys itself.
Chapter 4 – Setting up the Player Gadget
Rightio, in the default player gadget, create 3 new action programs. Name them KI_Blast_01-03 (or your own naming convention if you have one), If your hero has a standing and walking action program, you need to set your “Next Action Program” options, in the standing program, highlight KI_Blast_01. Now set your condition to an Key Command, B button being the button to input (status “Upon Pressing”). Also check the "The designated memory's value changed" checkbox, you’re variable being whatever variable you select to hold the number of projectiles, for example, if it’s a bow and arrow, you’d put up a condition that if variable “Number of Arrows” is greater than (>) 0. For the sake of this Tutorial, the variable will be “Player Magic” and if it’s greater than or equal to 5. Also make sure you’ve got the “Branch if All Conditions are met”, this will ensure that the player doesn’t ALWAYS fire KI blasts, even when he’s not doing anything.
Figure 4.1 – The Conditions
Cool, now go to the KI_Blast_01 action program. In the Selected Motion Programs Settings section, make sure you have the “Don't designate a direction of movement” and the “Ignore direction change while in motion” boxes checked. Also set the move speed down to 0. This ensures that the player can’t walk or move around while this is happening. The only “Next Movement” conditions you set are for KI_Blast_02. Check the “The set time elapsed” box and add a time you want. I’ve found that 0.2 works the best, and also we need to see if the player still has enough magic (or arrows/bullets) before moving onto KI_Blast_02, so we check if the magic is still greater or equal to 5.
KI_Blast_02 is set up the exact same as 01, except the only change we need to make is to check the “Shoot projectiles” box, and selecting Shot 1. The Next Movement conditions need to apply to Standby, and KI_Blast_03, the change to Standby only applies if half a second has passed without the player pressing the B Button again. The change to KI_Blast_03 occurs if the Player presses B again, and the Magic is >= to 5, and after 0.3 seconds pass.
KI_Blast_03 is almost exactly the same as 02, except instead of changing from 02 to 03, it changes from 03 to 02, and this allows the player to have continuous firing.
Chapter 5 – Setting up the Projectile Gadget
We’re nearly done with this surprisingly lengthy tutorial. The projectile gadget itself isn’t hard to set up. Create a new gadget and call it something like KI Blast, it needs a total of 6 movement programs, four for each direction it moves and the Exploded and Gone animations. For your 4 directions, in the Action Details section, set your direction corresponding to the sprite, make the movement speed 200% and tick the “Change Variable” box, the variable being hero magic, make sure the Add radio button is highlighted and the Value being -5.00. Repeat this for all directions.
Figure 5.1 – Directional Action Details
Now we need to set some conditions for the directions to change into the “Exploded” Movement Program. Select the “Branch if any Condition has been met” radio button, check the “Next step hits a wall”, and “Collided with another gadget” boxes so it destroys itself when it collides with them. In the action details section for your Exploded movement program, you need to check the “Don't designate a direction of movement” box and set the Movement speed to 0, so it doesn’t go anywhere, set a condition to go to the Gone event after 0.3 seconds. The Gone action details are the same as the Exploded, with the addition of checking the “Disappear” box. Now we need to go to the “Moving and Jumping Settings” tab and set the move speed to 2 for the X and Y directions.
Nearly done, what we do now is go back to the Player gadget and under the Projectile Settings tab, we set Shot 1 as our Ki Blast Gadget at Linkage Point 1. Set the Bullets per launch to 1, Fire rate left at 0, and the Continuous Fire Limit to 5. Also select the None Designated radio button and check the “Match direction with a shooter” box.
Figure 5.2 – Bullet Settings
Right, give ‘er a test play and see the fruits of your labour. This has been Kyle_Katarn with another IGM tutorial. Happy game making.