Guide 7 — The Magnet
Amarion Wilson
What you're building
A 2D side-scroller in the spirit of the first Sonic. The Magnet isn't actually a magnet — he's a guy in a suit with magnet gloves that pull metal toward him. You fight your way through masked criminals to a boss called Blaster.
You said in your pitch you're new to game design and wanted something simple. This guide is built around that: the core game is a platformer with enemies, which you'll have running in about an hour, and the magnet is a mechanic you bolt on afterward. If you stop after section 6 you still have a complete game.
You also already have three sprites drawn — The Magnet, Blaster, and the masked criminal — which puts you ahead of most of the class. Use them from the start. Building against real art is more motivating than grey boxes.
Time: about two hours for the platformer, another hour for the magnet.
1. Before you start
- Finish Guide 0.
- Read Guide B §B1 (player) and §B4 (enemy).
- One new input action:
Magnet. See section 7.
2. Scripts you'll use
Core — Guide B §B1, §B2
PlayerController2D · PlayerAnimatorBridge · Health · DamageOnContact · Checkpoint · RespawnManager · CameraTargetAssigner · SceneLoader · GameManager · AudioManager · HUDController · ParallaxBackground
Combat (Tier 2)
Team · Hurtbox · Hitbox · Knockback · MeleeAttack · EnemyPatrol · Projectile · ProjectileShooter · BossController · BossArenaTrigger
The magnet (Tier 3)
MagnetPull · MetalObject
Level (Tier 4)
Breakable · KillZone
3. Build The Magnet
Follow Guide B §B1 with your Magnet sprite, then set:
| Component | Setting | Value |
|---|---|---|
Health | Max Health | 3 |
| Invulnerability Time | 1 | |
| Flash While Invulnerable | ✓ | |
PlayerController2D | Move Speed | 8 |
| Jump Force | 14 | |
| Acceleration | 60 |
Add Knockback: Stun Duration 0.25, Resistance 0.
The two children
Hurtbox — trigger collider slightly smaller than the sprite, Hurtbox component with Team = Player, object layer Hurtbox.
AttackHitbox — trigger collider positioned in front of him, Hitbox component:
| Field | Value |
|---|---|
| Target Team | Enemy |
| Damage | 1 |
| Knockback Force | 8 |
| Knockback Upward | 3 |
Object layer Hitbox. Untick the GameObject checkbox so it starts disabled.
Because the hitbox is a child, it flips automatically when The Magnet turns around. That's why it goes on a child rather than the root.
Melee attack
Add MeleeAttack to the player root:
| Field | Value |
|---|---|
| Player Controlled | ✓ |
| Hitbox | drag AttackHitbox in |
| Windup | 0.08 |
| Active | 0.12 |
| Recovery | 0.2 |
| Use Animation Events | ✗ (for now) |
| Stop While Attacking | ✓ |
| Animator Trigger | Attack |
| Sfx Name | swing |
Those three timings add up to 0.4 seconds. When you make an attack animation later, match its length to 0.4 — or change these numbers to match your animation. A 1-second swing animation with a 0.4-second script makes the character flail after the hit is gone.
4. Build the masked criminal
Follow Guide B §B4 with your criminal sprite:
| Component | Setting | Value |
|---|---|---|
Health | Max Health 2 · Destroy On Death ✓ · Invulnerability 0 | |
Knockback | Resistance 0 | |
EnemyPatrol | Speed 2 · Turn Mode Sensors · Pause At Turn 0.3 | |
Ground Layer → Ground |
Children:
WallCheck(in front, chest height) andLedgeCheck(in front, below the feet) → drag both intoEnemyPatrolHurtbox— Team = Enemy, layerHurtboxBodyHitbox— Target Team = Player, Damage 1, Repeat Delay 1, layerHitbox, left enabled
Save as a prefab. This is the enemy you'll place most.
The ledge check matters
Without LedgeCheck, criminals walk off platforms and die in pits, which looks broken. Put the empty child slightly in front of the feet and slightly below them, and set Check Distance to about 0.15.
5. Build the level
- Tilemap or sprites for ground, all on Layer →
Ground, with colliders - A wide
KillZone(trigger collider +KillZonecomponent) under everything Checkpointprefabs (trigger +Checkpoint) at intervals- A
LevelExitat the end (trigger +LevelExit, Requirement None, Destination Next In Build) - Camera per Guide B §B3, with a confiner
Prototype with grey rectangles, then swap in art. Your sprites are pixel art — set their Filter Mode to Point (no filter) and Compression to None in the import settings, or they'll look blurry.
6. Playtest the platformer
Stop and play before adding the magnet. You should have:
- The Magnet runs and jumps
- Attack swings and kills a criminal in two hits
- Criminals patrol and turn at ledges and walls
- Touching a criminal costs a heart
- Dying respawns you at the last checkpoint
If all five work, you have a game. Everything from here is enhancement.
7. Add the magnet gloves
Now the fun part.
First: the input action
Open your input actions asset (Guide 0 §6):
- Under the Player map, click + → name it exactly
Magnet - Action Type Button
- Add Binding → Path → Listen → click the right mouse button (or pick a key like
Q) - Save Asset
Then: the hold point
Right-click Player → Create Empty, name it HoldPoint. Position it about one unit in front of the chest. This is where pulled objects come to rest.
Then: the component
On Player, add MagnetPull:
| Field | Value | What it does |
|---|---|---|
| Metal Layer | Metal | what can be pulled |
| Radius | 6 | how far the pull reaches |
| Cone Angle | 60 | degrees each side of facing — 180 pulls from all around |
| Pull Force | 30 | tune this by feel |
| Max Objects | 3 | how many at once |
| Hold Point | drag HoldPoint in | |
| Grab Distance | 0.8 | when an object snaps into your hands |
| Throw Speed | 18 | |
| Can Hold | ✓ | |
| Pull Sfx | magnet | |
| Throw Sfx | throw | |
| Beam Prefab | (optional, see below) |
How it plays
Hold Magnet to pull metal objects toward you. When one reaches your hold point it snaps into your hands. Press Attack while holding to throw it. Release Magnet to drop it.
The orange gizmo shows the radius and cone when the player is selected. Use it to check the cone points the right way.
Optional: the beam
Make a prefab with just a Line Renderer (2 positions, width 0.05, a material assigned — a Line Renderer with no material renders bright magenta). Drag it into Beam Prefab and you'll get a visible line to each pulled object. Cheap and it makes the mechanic legible.
8. Build metal objects
A metal crate
- Empty GameObject
MetalCrate+ Sprite Renderer. - Rigidbody2D — Dynamic, Mass 1, Linear Damping 1.
- Box Collider 2D (solid, not a trigger).
- Layer →
Metal← without this, nothing happens. - MetalObject component:
| Field | Value |
|---|---|
| Damage While Flying | see below |
| Fly Time | 1.5 |
| Settled Speed | 1.5 |
| Break On Impact | ✗ |
- Also add a DamageOnContact:
| Field | Value |
|---|---|
| Target Tag | Enemy |
| Damage | 2 |
| Instant Kill | ✗ |
| Knockback Force | 6 |
- Untick the DamageOnContact component's checkbox so it starts off, then drag it into
MetalObject's Damage While Flying slot.
Now the crate is harmless lying on the ground and dangerous while flying. That's the whole trick.
- Save as a prefab.
A breakable metal barrier
Same as above, plus:
- Health — Max Health 3, Destroy On Death ✗, Invulnerability 0
- Breakable — Min Damage To Break 2, with Loot Prefabs if you want it to drop something
- A
Hurtboxchild with Team = Neutral (so anything can hit it)
Min Damage To Break 2 means your fist (Damage 1) won't open it but a thrown crate (Damage 2) will. That's a puzzle made from two numbers.
9. Build Blaster
Your boss shoots. BossController assembles him from parts.
- Empty GameObject
Blaster, Tag →Enemy, your Blaster sprite, Rigidbody2D, Capsule Collider 2D. - Add:
- Health — Max Health 20 · Invulnerability 0 · Destroy On Death ✗
- Knockback — Resistance 1
- BossController — Start Automatically ✗ · Face Player ✓
- Child
Hurtbox— Team = Enemy, layerHurtbox. - Child
FirePoint— an empty in front of his gun. - Add ProjectileShooter to the Blaster root:
| Field | Value |
|---|---|
| Projectile Prefab | your bullet prefab (next) |
| Fire Point | the FirePoint child |
| Team | Enemy |
| Mode | Manual ← the boss controller fires it |
| Aim | TowardPlayer |
| Fire Rate | 0.3 |
| Shots Per Fire | 1 |
| Spread Degrees | 0 |
The bullet prefab
Sprite + Rigidbody2D (Gravity Scale 0) + Circle Collider 2D (Is Trigger ✓) + Projectile:
| Field | Value |
|---|---|
| Damage | 1 |
| Speed | 12 |
| Lifetime | 3 |
| Pierce | 0 |
| Blocking Layers | Ground |
| Face Direction | ✓ |
The phases
On BossController, add two phases:
Phase 1 — Health Percent 100, Rest Between Attacks 1.5
| Attack | Duration | Weight | On Execute |
|---|---|---|---|
SingleShot | 0.5 | 2 | ProjectileShooter.Fire |
Reposition | 1.0 | 1 | (empty, or a move script) |
Phase 2 — Health Percent 50, Rest Between Attacks 0.8
| Attack | Duration | Weight | On Execute |
|---|---|---|---|
SingleShot | 0.4 | 2 | ProjectileShooter.Fire |
TripleShot | 0.8 | 1 | ProjectileShooter.Fire ×3 (add three entries to the same event) |
- Add a
BossArenaTriggerat the arena door, dragBlasterin, and put a wall object in Barriers.
A magnet-flavoured boss idea
Here's something your mechanic makes possible that nobody else in the class can do: give Blaster a metal shield plate as a separate object on the Metal layer, positioned in front of him, with a collider that blocks your attacks. The player has to pull the shield off with the magnet before they can hurt him.
To build it: a child object of the arena (not of Blaster, so it can be pulled away), on the Metal layer, with a Rigidbody2D and a MetalObject. Put Blaster's Hurtbox behind it. It's a few minutes of work and it makes the boss about your mechanic rather than just a health bar.
10. The HUD
- Canvas → three heart Images in a row, top-left (
Heart1,Heart2,Heart3). - Empty child
HUDwith HUDController. - Add all three hearts to the Heart Icons list, and assign Heart Full and Heart Empty sprites.
11. Wire it up
| On this object | Event | Drag in | Choose |
|---|---|---|---|
Player → Health | On Died | RespawnManager | RespawnManager.OnPlayerDied |
Player → Health | On Health Changed | HUD | HUDController.UpdateHealth (Dynamic) |
Player → PlayerController2D | On Jumped | AudioManager | PlaySFX (string) → jump |
Player → MagnetPull | On Magnet On | AudioManager | PlaySFX (string) → magnet |
Blaster → BossController | On Boss Defeated | GameManager | GameManager.LevelComplete |
Blaster → BossController | On Phase Changed | AudioManager | PlaySFX (string) → boss_phase |
12. Magnet playtest
With a metal crate in the level:
- Hold Magnet near a crate — it slides toward you. If nothing moves: is the crate on the
Metallayer? Is Metal Layer set onMagnetPull? Is the crate a Dynamic Rigidbody2D? - The crate snaps into your hands when it gets close.
- Press Attack while holding — it flies forward.
- A thrown crate hurts a criminal, a resting one doesn't.
- The cone works — face away from a crate and it shouldn't pull.
If crates orbit around you rather than settling, lower Pull Force to 20. If they crawl, raise it. This one genuinely needs tuning by feel.
13. Then add
- More level. Your systems are done after section 9.
- Animation — Guide B §B6, plus an
Attacktrigger. You have sprites; a four-frame walk and a two-frame swing goes a long way. ParallaxBackground— a city skyline. Depth 0.2 for distant buildings, 0.5 for closer ones.- A criminal with a metal weapon you can yank away: give the weapon its own Rigidbody2D on the
Metallayer. Advanced, but very on-theme. Breakablewalls that need a thrown crate to open.- Sound: a magnetic hum while pulling, a clang on throw, punch impacts.
14. Design notes for your game specifically
You said you wanted something simple, and this is the right instinct. A short, finished, polished level beats an ambitious unfinished one every time. If you get the platformer working and add nothing but the magnet, you'll have made a real game.
Use the magnet for puzzles, not just damage. Throwing crates at enemies is fine, but the mechanic gets interesting when it's the only way past something: a crate you have to pull down to stand on, a barrier that needs a thrown object, a boss shield you have to strip. One good puzzle beats ten thrown crates.
The suit is a good excuse. He's not a superhero, he's a guy with equipment — which means the gloves can have limits (range, cone, how many objects) and those limits are the game. The cone angle in particular is worth keeping fairly narrow; pulling from all directions is less interesting than having to face what you want.
Two hits to kill a criminal is right. One hit and there's no combat; three and it drags. If you add tougher enemies later, add them alongside the weak ones rather than replacing them.
15. Common problems
| What you see | What's wrong |
|---|---|
| Attack does nothing | AttackHitbox not assigned to MeleeAttack, or hitbox not disabled at start, or teams wrong |
| Attack hits through walls | Hitbox child isn't on the Hitbox layer |
| Criminals walk off ledges | LedgeCheck missing or positioned wrong |
| Criminals walk through walls | WallCheck missing, or Ground Layer not set on EnemyPatrol |
| Criminals face the wrong way | Untick Art Faces Right on EnemyPatrol |
| Magnet does nothing | Magnet action missing from the input asset; or objects not on the Metal layer; or Metal Layer unset |
| Objects orbit instead of settling | Pull Force too high — lower to 20 |
| Objects crawl slowly | Pull Force too low, or object Mass too high |
| Can't grab objects | Can Hold unticked, or Grab Distance too small |
| Thrown crate does no damage | DamageOnContact not assigned to Damage While Flying, or its Target Tag isn't Enemy |
| Resting crate hurts enemies | You left the DamageOnContact component enabled — untick it |
| Boss never attacks | Start Automatically ✗ with no BossArenaTrigger, or the phase has no attacks |
| Boss bullets pass through walls | Blocking Layers not set to Ground |
| Pixel art looks blurry | Set the sprite's Filter Mode → Point (no filter), Compression → None |