Part 3: Let’s Set Up Firing the Bullet on the Player Side!
Next, let’s configure the bullet on the player side.
There are two steps: register “Fire Bullet” (the fire bullet object) in the bullet data under the “Bullet” settings, and add the “FireBullet” action.
Part 3-1: Let’s Configure the “Bullet” Settings!
- Go back to the Object view and switch the object to “Player”.
- Press “+ Add Settings” in the upper left.
- In the Add Settings window, add “Bullet” from Using objects.
- Look at the Inspector on the right, click “Array[BulletData]” in the bullet data list to expand it, then click the “BulletData” that appears to expand that too.
- Expand the base settings. First set the bullet name to Fire Bullet, then add “Fire Bullet” from the “List” button of the bullet object path.
- Next, turn on “Unlimit Shots” in the base settings (if this is off, you cannot fire while a fire bullet already exists in the scene). If the base settings look like the image, you are good.
- Next, expand “Initial Behavior” and set it to “Fly in the display direction of the firing object”.
- The bullet data side is now set. You have created data that fires the “Fire Bullet” “in the display direction of the firing object”, “no matter how many fire bullets are already in the scene”.
Part 3-2: Let’s Set Up the “FireBullet” Action!
-
Go into “Edit Visual Script”, create a new state near the “Move” state, set the animation category name to “shoot” and name it “Ground Shot”.
-
Press “+ Add Executable Action”. In the left pane choose “FireBullet” under “Attack/Bullet”, and in the right pane select the bullet data “Fire Bullet”, then press “Add”. If Fire Bullet is not there, check that it is correctly set in the player’s “Bullet” settings.
-
The action side is done, so let’s make the link. Add a link from the “Move” state to “Ground Shot”, check “Trigger On Input”, and press “+ Add Input”.
-
Set the left pane to the registered key used for input, and the right pane to Input Key: B, Input Condition: Moment Pressed, then press “Add”.
-
As things stand you can only fire the fire bullet while moving, so let’s connect it from Idle too. The contents are exactly the same, so copy the “Move” → “Ground Shot” link, paste it onto Idle, and connect it to Ground Shot.
-
Finally, make a link back from “Ground Shot” to “Idle” and set the state transition condition to “FINISHED_ANIMATION” (the animation has finished). Now it returns to Idle once the “shoot” animation ends.
-
That is the setup done, but the lines may look messy. States can be moved by dragging, so this is a good chance to move them around and tidy things up a little. (In the image below, all the states have been moved down and Ground Shot has been moved up.)
-
Now let’s test play. If everything is set up correctly, a fire bullet comes out in the direction the player is facing and travels forward while bouncing. Note that “at this point, even with correct settings, the bullet disappears but cannot defeat enemies”. Just check that the bullet comes out and that it bounces as it travels.
Checklist for when it does not work
- No bullet comes out.
Check that the bullet data is correctly specified in the “FireBullet” action. - The bullet comes out, but you cannot move afterwards.
Check that the link back to Idle is set correctly, and that the shoot animation is correctly assigned to the Ground Shot state. - The bullet comes out, but not from the second shot onward.
Check that “Unlimit Shots” is correctly turned on in the bullet data’s base settings. - The bullet comes out, but does not bounce.
Check whether the template move type Bound is correctly set in the Move state,
and whether you accidentally enabled the Down direction in “ContactWithBody”.
Part 3-3: Let’s Make Bullets Able to Defeat Enemies
At this point, even with correct settings, the bullet hits the enemy and disappears — and damage really is dealt and the HP reaches 0 — yet the enemy does not perform its damage motion.
The reason is that the transition condition to the “Damage” state is contact with the “player” group only, and contact with “player_bullet”, which the player’s bullet belongs to, is not set. Let’s fix that right away.
-
Go back to the Object view, open “Enemy” and press “Edit Visual Script”. Copy and paste the Damage state.
-
A state called Damage (1) is created, so change its title to “Fire Bullet Damage” and delete the “SetObjectVelocity” that is set on it. (SetObjectVelocity is the action that bounces the player up, and we do not want a bounce from a bullet.)
-
Copy the walk → Damage link and paste it as a walk → Fire Bullet Damage link.
-
Open “ContactWithAttackArea” in the Inspector and change the target object group to “Player_Bullet”.
-
Next, copy the Damage → Dead condition in the same way and paste it as a Fire Bullet Damage → Dead link.
-
That is everything. Being hit by the player’s bullet now links to Fire Bullet Damage, and once HP reaches 0 it should carry through to Dead. Let’s try it in a test play.
Checklist for when it does not work
- The bullet does not stop at the enemy.
Check the “ContactWithHitArea” condition on the fire bullet object. - The bullet disappears but the enemy does not.
Check the conditions on the enemy’s walk → Fire Bullet Damage link and Fire Bullet Damage → Dead link.
The next tutorial is in the table of contents
Extra Challenges
You should now understand how to fire bullets and how to set up animations, so the tutorial ends here… but as a game there are probably a few things that bother you. Here are the solutions, so give them a try if you are interested.
You cannot fire in the air.
Copy Ground Shot, create an “Air Shot” state, and link to it from the “Jump” state and the “Fall” state.
From the “Air Shot” state, link only to the “Fall” state.
All the settings can be the same as Ground Shot.
-
Why not return to “Jump”?
Because returning to Jump would make the character jump again. -
Why separate “Ground Shot” and “Air Shot”?
To separate where they return to. If Air Shot returned to “Idle”, the character would be able to jump in mid-air after firing.
The enemy behaves strangely when you increase its HP.
As built now, the enemy cannot return to the walk state after taking damage. (It is built on the assumption that HP is only 1.)
Let’s add links back to walk from “Damage” and “Fire Bullet Damage”.
On those links, set the condition “SwitchVariableChanged” with HP > 0, and you get a setup where the enemy returns to walk if HP is greater than 0 and moves to dead if HP is 0.
Also, since you have gone to the trouble of separating the states, you can load a new official particle (explode, for example) and use “DisplayParticle” in the Fire Bullet Damage state to show a different particle only when the enemy is hit by a fire bullet.





















