Tutorial: Script Course #1 Let's Create a Shooting Attack.

In this course, you will learn the basics of script creation using ACTION GAME MAKER.
In the first session, we will create an attack.

Important Notes When Working with Visual Scripts

  • Visual Scripts and Tabs
    Due to Godot’s specifications, you can freely open any script screen regardless of which scene tab is currently open in the editor. However, in Visual Scripts, the system retrieves and uses node information from the currently open scene tab. Therefore, if you attempt to configure a Visual Script while a scene tab without an attached Visual Script is open, the system will be unable to retrieve node information, resulting in failures to access animation, variable, or switch data. Please note that if you accidentally open the wrong tab, simply returning to the correct tab without making any changes to the Visual Script will not cause any issues.

  • Visual Scripts and Reference Files
    Due to limitations in Godot’s specifications, the “Path to Specify Other Objects” for each action is stored as string data. Consequently, if you move the target game object within the file system, the reference will point to a non-existent location. Although we provide a Missing Check feature to verify whether the referenced data can be accessed, reconfiguring references after development has become large-scale is extremely difficult. We strongly recommend organizing your folders before starting development.

Preparations Before Starting the Course

For this course as well, we will use the tutorial project from the initial tutorial.
Please open the project and prepare accordingly.

STEP 1: Create a Bullet Object - Bullet Settings

  1. Create a new game object scene. Click the + button on the tabs in the central editor window to open a new tab, then select “Game Object” in the Scene window.
  2. In the object creation screen, configure the settings as shown below and click the Create button.
    Object Name: Any name (use “sample_bullet” here)
    Template: bullets
    Type: bullet_base
    Group: Player
  3. A game object scene with basic settings will be generated. First, save it. Right-click the unsaved tab or use the Ctrl+S shortcut to save it to any location.
  4. We would like to set an image, but none is available. For now, let’s use a node that draws a rectangle in Godot. Click the + button in the top-left corner of the Scene window.
  5. Select and create the ColorRect node located under Node > CanvasItem > Control. It is helpful to search using “Color” or “Rect” in the search bar.
  6. A white rectangle has been generated. Since there is no reference for comparison, it may be hard to see, but it is very large, so let’s make it smaller. Select the ColorRect node created in the Scene window.
  7. In the Inspector window, expand Layout > Transform. The size is 40x40, which is very large, so let’s reduce it to around 4x4.
  8. Since it is created from the origin towards the bottom-right, let’s make the center the origin. Set Position to x=-2, y=-2. Now the scene’s origin is in the center.
    image
  9. The red semi-transparent rectangle (AttackCollision) represents the attack range, but it seems too large. Let’s make it smaller. Select AttackCollision in the Scene window.
  10. Select the four corners and resize it to be slightly larger than the ColorRect.
  11. The light blue semi-transparent rectangle (CollisionShape2D) is for wall collision detection. As is, the attack will be blocked by walls, so let’s make the walls slightly smaller than the attack range.
  12. Next, select the MoveAndJumpSettings node. The initial values for horizontal/vertical movement speed are 100px per second, which is very slow, so let’s set them to around 300px.
  13. For a normal object, animations and basic settings would be required, but since this bullet is simple, no additional settings are needed.

STEP 2: Create the Bullet Object - Bullet Script

  1. Create a new script. Click the :scroll: icon at the top of the Scene window to create a new script.
    image

  2. Ensure the language is set to VisualScript, then give it any name and create it.

  3. Rename the first node to “Move” and enable the option to ignore gravity.

  4. From Actions > +Add Executable Action, add an attack configuration as an executable action. Specify the hit group to be “Enemy” only. This prevents the attack from hitting the player.

  5. Next, add a new state via Add State and name it “Remove”. Also enable the option to ignore gravity for this state.

  6. Add the executable action “RemoveSelf” to the Remove state. This process removes the object itself from the game. Objects like bullets and enemies must be removed after they have fulfilled their role; otherwise, they will persist indefinitely and consume resources, so be sure to remove them.

  7. Finally, right-click “Move” to create a link and connect it to “Remove”.

  8. Set three removal conditions. The first is when hitting an enemy. From the Inspector, go to Conditions > Add Condition and add “ContactWithHitArea”. Since you want to detect contact from any direction, set the detection direction to “All” and the target group to “Enemy”.

  9. Set the second condition. Follow the same procedure to add “Offscreen”. Set the target type to this node, and set the logical condition with the previous condition to OR. If this remains AND, the transition will not occur unless both conditions are met.

  10. Set the third condition. Follow the same procedure to add “ContactWithTile”. Since you want to detect contact from any direction, set the detection direction to “All”. Set the logical condition with the previous condition to OR.

  11. Now, the object will be deleted when it hits the enemy group OR goes off-screen OR contacts a tile.

TIPS

Actions: Remove vs. RestoreRemove, Disable vs. Enable
You may have noticed similar conditions; here is an explanation of how to distinguish between them.
“Remove” completely deletes the object from the game, making it suitable for objects that do not need to be reused. While “RestoreRemove” can bring it back, it actually re-generates the object, resetting its previous state.

“Disable” only temporarily stops the object from functioning without removing it from the game. Therefore, using “Enable” allows it to return to its original state exactly as it was. This is convenient, but objects in the “Disable” state still consume resources, so it is safer to “Remove” objects that have no intention of being reused.

Configuring a Disappearance Animation
In this case, no animation was set, so the object disappears immediately. However, if you set an animation on the “Remove” action, it will disappear before the animation plays.
If you wish to set one, it is recommended to add a “Hit” state between “Remove” and “Move”.
When the hit condition is met, transition to the “Hit” state to play the animation. Then, transition to the “Remove” state when the condition “Animation Finished” or “Time Elapsed” is met.

STEP 3: Set up the player’s bullets and gun.

  1. Return to the Object_Sampleplayer tab.

  2. Click the Add Node button in the top-left corner of the Scene view.

  3. Add the BulletSettings node from Node > AGMaker. This node manages the bullets to be fired.

  4. Configure BulletSettings as the object that fires the bullets as follows:

  5. Expand BulletDataList → Add Bullet (+Add Bullet) → → NewBulletData to create new bullet data.

  6. Configure the basic bullet settings. Expand BulletData > Bullet Base Settings and select as follows:
    Name: Enter any name; here we use Sample_Bullet.
    Object Path: Specify the sample_bullet created earlier. Please note that if you move sample_bullet.tscn, the reference will break and it will stop working.
    Unlimited Bullets: On *This will be explained later.

  7. Next, configure the initial behavior. Expand Initial Behavior and set the initial behavior to FireObjectDirection (fire in the direction the object is facing).

  8. Bullet configuration is now complete. You can now fire sample_bullet in the object’s facing direction using the fire action. Next, we will equip a gun.

  9. Select AnimationPlayer and try playing 044_Gun_Aim from the animations. The gun-firing animation will play… but the character is still bare-handed.

  10. The gun image itself is included in the templates folder under File System > objects > weapons > P_other as W_005_gun.png. Let’s use this. It seems to work well if we attach this gun to the left-hand bone.

  11. Return to the Scene window and select BoneAnimationRoot2d > Skeleton > B_Chest > B_Joint_L > B_Arm_L > B_Hand_L > B_Weapon_L.

  12. With B_Weapon_L selected, drag W_005_gun.png from the File System near the hand and drop it while holding Shift.

  13. Dropping while holding Shift makes it a child of the selected node, so W005Gun should be added as a child of B_Weapon_L. If this doesn’t work, move it manually.

  14. It is placed, but the angle is wrong, so let’s fix it. Select W005Gun and adjust the Position and Rotation under Node2D > Transform.
    Setting it approximately to x:12, y:21, Rotation:156.4 should make it look correct.
    Note: The reason it appears tilted even at 0 degrees is that the parent bone is already tilted by the animation.

  15. Play the animation to confirm it moves correctly. If there are no issues, the next step is to set the muzzle, which is the firing point.

  16. Use a Connector node for the firing point. This sample character already has a node named Connector - gun fire, but for some reason it is located near the feet, so let’s adjust it. Adjust its position like the gun graphic and move it to the muzzle area.

  17. Now, the bullet, gun, and muzzle settings are complete.

Explanation of Bullet Settings

Basic Settings
Shot Count: The number of times to fire in one action. This can replicate rapid fire or shotguns, but be careful that if the state changes during firing, it may stop midway.
Fire Interval: Used together with Shot Count; this is the interval between shots. Setting this to 0.3 seconds will fire one bullet every 0.3 seconds, and setting it to 0 will fire all bullets simultaneously.
Bullet Display Limit (Shit Limit): The maximum number of bullets that can be displayed on screen. If this is set to 1, you cannot fire until existing bullets disappear.
Initial Behavior
Initial Behavior: Specifies how the fired bullets move. If a movement script is set on the bullet side, the bullet-side script takes precedence.
Spread Range: Specifies the spread range of the bullets.
Spread Type: Specifies how the bullets spread. Fixed means firing at equal intervals within the firing angle, Wiper means firing while moving up and down within the firing angle, and Random means spreading randomly within the firing angle.
In-flight Behavior
In-flight Behavior: Allows specifying behaviors such as tracking a locked-on target or drawing a boomerang trajectory. If a movement script is set on the bullet side, the bullet-side script takes precedence.

STEP 4: Let’s Fire a Bullet.

  1. Click the :scroll: icon next to the Player to open the Visual Script.
  2. Create a new state named “Shoot” near “Idle” and set the animation to 044_Gun_Shoot. If no animation appears, please check that you have the Object_SamplePlayer tab open.
  3. Add an action to fire a bullet by setting the “FireBullet” action. Select “Sample_Bullet” as the bullet data and specify “Connector - gun fire” as the connection point. This will make the Sample_Bullet fire from the muzzle.
  4. Link from “Idle” to “Shoot”. Set the transition condition to “While the X button (C key on keyboard) is pressed”.
  5. Link from “Shoot” back to “Idle” as a shortcut. Set the transition condition to “When the animation finishes”.
  6. Now, if everything is set up correctly, you should be able to fire a bullet. Try a test play by pressing :play_button: or the F5 key. If the bullet is fired, hits a tile, and disappears, you have succeeded.

Troubleshooting if it doesn’t work

The firing animation does not play
It is likely that the transition is failing. Please check if the animation is properly set and if the transition settings from Idle to Shoot are correct.

Stuck in the firing animation
Similarly, the transition is likely failing. Check if the transition from Shoot back to Idle is set up correctly.

No bullet is fired
The bullet firing action might not be set up correctly.
Check if the bullet data is set correctly in the firing action.
Check if the connection points are set properly.
Check if the connection point is located at the muzzle position.

Can only fire one bullet
In BulletSettings, the number of visible bullets might not be set to unlimited.

Bullets do not disappear
Check the Visual Script of the sample_bullet object. Verify that a “Disappearance” action is set in “Remove” and that the three transition conditions are connected with OR.

Part 2 is here: