Summary of "GameMaker Studio 2: Complete Platformer Tutorial (Part 3: Shooting & Recoil)"
GameMaker Studio 2: Complete Platformer Tutorial (Part 3: Shooting & Recoil) - Summary
This tutorial focuses on adding shooting mechanics and recoil effects to a platformer player character using GameMaker Studio 2.
Storyline / Context
- The player character is enhanced with a gun that can shoot bullets.
- The tutorial is part of a series aimed at building a complete Platformer Game.
Gameplay Highlights
- The player can aim the gun with the mouse.
- Bullets are fired towards the mouse pointer.
- A Muzzle Flash effect is created at the gun barrel.
- The gun exhibits recoil when firing, adding a sense of weight and realism.
- Controls are adapted to WSAD for easier movement while aiming with the mouse.
- Bullets collide with walls and get destroyed on impact.
Step-by-Step Implementation & Key Tips
1. Adding the Gun Sprite and Object
- Import a Gun Sprite (
s_gun). - Set the gun’s origin point between the player’s hands for proper rotation.
- Create a gun object (
o_gun) and assign the Gun Sprite. - Place the gun on a separate layer above the player to ensure correct drawing order.
- Make the gun object follow the player’s position with a slight lag using the Begin Step event to simulate weight.
2. Making the Gun Aim Towards the Mouse
- Use
image_angle = point_direction(x, y, mouse_x, mouse_y)to rotate the gun towards the mouse. - Handle flipping the Gun Sprite vertically when aiming left (angle between 90° and 270°) by toggling
image_y_scalebetween 1 and -1.
3. Adjusting Controls for Mouse Aiming
- Change movement keys from arrow keys to WSAD.
- Use logical OR (
||oror) in code to allow either arrow keys or WSAD keys to move the player.
4. Creating the Bullet Sprite and Object
- Import a 2-frame Bullet Sprite (
s_bullet), where:- Frame 0 = Muzzle Flash (big white circle).
- Frame 1 = bullet image.
- Set bullet animation speed to 60 FPS to show Muzzle Flash for exactly one frame.
- In the bullet object (
o_bullet):- Use Animation End event to stop animation and fix the frame to the bullet image (frame 1).
- Use Post Draw event to check collision with walls and destroy bullet on impact, allowing the Muzzle Flash to be visible before destruction.
5. Shooting Mechanic in Gun Object
- Add a
firing_delayvariable to control fire rate. - On left mouse button press and if
firing_delay < 0:- Create a bullet instance at gun’s position on the bullet layer.
- Set bullet speed (25 pixels/frame).
- Set bullet direction to gun’s current
image_anglewith a small random spread (random_range(-3, 3)degrees) for a machine gun effect. - Reset
firing_delayto 5 frames.
- Decrement
firing_delayeach frame.
6. Adding Recoil to the Gun
- Add a
recoilvariable initialized to 0. - When firing, set
recoil = 4. - Each frame, reduce recoil by 1 but clamp to zero using
recoil = max(0, recoil - 1). - Apply recoil to gun’s position by moving it backward along its facing direction using:
x = x - lengthdir_x(recoil, image_angle)y = y - lengthdir_y(recoil, image_angle)
- This creates a kickback effect making shooting feel more impactful.
Additional Notes
- The tutorial explains the difference between
step,begin step, andpost drawevents, and why specific events are used for certain logic. - The use of the
withstatement allows applying code to newly created instances (bullets) immediately after creation. - The tutorial emphasizes best practices such as layering for depth control and using origin points for proper rotation.
- The instructor mentions that resources used in the tutorial are provided in the video description for easy following.
Sources & Contributors
- Tutorial by Shaun Spalding (GameMaker Studio 2 educator)
- Special thanks to Patreon supporters:
- Inner Mule
- GES Montgomery
- Roxom Harold
- Gidry Dan
- Jason McMillan
- Angel Rodriguez
- Owen Morgan
This part of the tutorial builds a solid foundation for shooting mechanics with realistic recoil and visual feedback, setting up for further enhancements in the platformer series.
Category
Gaming
Share this summary
Is the summary off?
If you think the summary is inaccurate, you can reprocess it with the latest model.
Preparing reprocess...