How To Make A 2D Shooter
Technical

How To Make A 2D Shooter

by Anonymous · 2026-05-03

Building a 2D shooter game using Unity

5 chapters 3,892 words ~16 min read English 176 reads

Read the first chapter

The whole of chapter one, free. About 4 min. Turn the pages with the arrows, your keyboard, or a swipe.

Chapter 1

Unity 2D Project Setup & Input

What happens when your 2D shooter feels “off” even though the sprite and animation look correct? In most cases, the cause is camera setup, sprite scale/pivot, or input wiring via Unity’s Input System (new input handling).

This section sets up a clean Unity 2D project structure, configures an orthographic camera for pixel-consistent movement, and wires player movement using Unity’s Input System.

Overview

Use this section when starting a new 2D shooter project or when input/camera behavior is inconsistent across machines. It covers: (1) project settings for 2D rendering, (2) camera configuration for orthographic viewing, (3) sprite import/pivot alignment, and (4) Input System code for movement using PlayerInput an InputAction.

Quick Reference

• Camera (2D) Transform.position.z = -10 (typical)

• Player movement input: Vector2 move = context.ReadValue<Vector2>();

• Unity Input System components:

• PlayerInput (behavior: “Send Messages” or “Invoke Unity Events”)

• InputActionAsset with an action named Move

• Movement API: Rigidbody2D + rb.velocity = new Vector2(x, y) * speed;

• Common axis mapping: WASD/Arrow keys -> gamepad left stick -> Vector2

Parameters

Parameter

Type

Required

Description

move

Vector2

Yes

2D movement vector from the Move action (X=left/right, Y=down/up).

speed

float

Yes

Units per second applied. Example default: 6.0.

useFixedUpdate

bool

No

applying

inputActionName

string

Yes

Name of the action inside. Example: "Move".

deadZone

float

No

Gamepad stick dead zone. Default: 0.125 (if configured in the action).

cameraSize

float

No

Orthographic size. The default depends on your world scale; start with that 5 for many 2D setups.

cameraZ

float

No

Camera Z position. Default: -10 for typical 2D scenes.

Code Example

using UnityEngine; using UnityEngine.InputSystem;

[RequireComponent(typeof(Rigidbody2D))] public class PlayerMovement2D: MonoBehaviour { [Header("Movement")] [SerializeField] private float speed = 6.0f;

[Header("Input")] [SerializeField] private string inputActionName = "Move";

private Rigidbody2D rb; private Vector2 moveInput;

private InputAction moveAction;

private void Awake() { rb = GetComponent<Rigidbody2D>();

// Assumes you assigned an InputActionAsset via PlayerInput OR created one in code. // If using PlayerInput, you can fetch the action from PlayerInput.actions. var playerInput = GetComponent<PlayerInput>(); if (playerInput == null) { Debug.LogError("PlayerMovement2D requires a PlayerInput component on the same GameObject."); enabled = false; return; }

moveAction = playerInput.actions[inputActionName]; if (moveAction == null) { Debug.LogError($"InputAction '{inputActionName}' not found in InputActionAsset."); enabled = false; return; }

// Bind callbacks to capture input as it happens. moveAction.performed += OnMove; moveAction.canceled += OnMove; }

private void OnDestroy() { moveAction.performed -= OnMove; moveAction.canceled -= OnMove; }

private void OnMove(InputAction.CallbackContext context) { // ReadValue<Vector2>() expects the action to be configured as a Vector2 control type. moveInput = context.ReadValue<Vector2>(); }

private void FixedUpdate() { // Apply in FixedUpdate for stable physics movement. Vector2 velocity = moveInput * speed; rb.velocity = velocity; } } Response Format

{ "project": { "renderingMode2D": true, "camera": { "projection": "Orthographic", "orthographic": true, "transformPositionZ": -10 }, "player": { "components": ["PlayerInput", "Rigidbody2D", "PlayerMovement2D"] } }, "input": { "inputActionName": "Move", "expectedValueType": "Vector2", "bindings": [ { "source": "Keyboard", "controls": ["W", "A", "S", "D"] }, { "source": "Gamepad", "controls": ["LeftStick"] } ] }, "movement": { "speed": 6.0, "applicationLoop": "FixedUpdate", "movementVectorMapping": { "x": "left/right", "y": "down/up" } } } Notes & Best Practices

• Input system value type must match code: ReadValue<Vector2>() requires the Move action to be configured for Value Type = Vector2; otherwise you’ll read zeroes or get binding warnings.

• Physics timing: set velocity FixedUpdate() when using Rigidbody2D to avoid frame-rate-dependent movement.

• Camera consistency: keep the camera orthographic and lock its Z position; changing orthographic size alters world-to-screen scale and affects perceived speed.

• Sprite pivot/import: ensure sprites have consistent pivot points (often bottom-center for ground movement) and avoid mixed pivots that make

• Sprite import scale: in the sprite import settings, keep it Pixels Per Unit consistent across sprites. If one sprite uses 100 PPU and another uses 16, collisions and movement alignment will drift.

• Screen-to-world mapping: for aiming and spawning later, cache Camera.main and rely on Camera.ScreenToWorldPoint the correct z value (usually -camera.transform.position.z for 2D).

• Input System lifecycle: enable/disable the PlayerInput component (or the action map) when pausing or switching scenes. If you leave actions enabled, callbacks keep updating moveInput.

• Edge cases: guard against missing PlayerInput or null values Rigidbody2D at edit time to prevent runtime nulls.

2D Launch Checklist (Unity project + Input System)

Use this checklist to verify the project is in a clean state before adding weapons, enemies, or shooting logic.

Check

Target value / setting

Where

Project type

2D template or equivalent (2D physics enabled)

Unity Editor

Render mode

The camera is set to orthographic.

Camera component

Camera transform

Z position constant (commonly -10 )

Camera transform

Rigidbody

Player uses Rigidbody2D

Player GameObject

Physics plan

Gravity scale set intentionally ( 0 for top-down, 1 for platformer)

Rigidbody2D

Player input driver

Player has PlayerInput with an InputActionAsset

Player GameObject

Move action

Value Type = Vector2, action name matches code (e.g., Move )

Input Actions asset

Movement timing

Apply movement in FixedUpdate

Movement script

No mixed pivots

Sprite pivots aligned for consistent collision/movement

Sprite Import settings

Related sections

• Input System action maps and rebinding (for supporting keyboard + gamepad)

• 2D physics movement tuning (drag, friction, gravity scale)

• Camera-based world coordinates (for mouse aiming and projectile spawn positions)

With a clean camera, consistent sprite import settings, and movement input wired through the Input System, the next chapter can focus on adding aim direction and projectile spawning using the same input pipeline.

End of chapter one. 4 more chapters in the full book.

1 / 5

Swipe or use the arrows to turn the page

What's inside: 5 chapters

  1. 1. Unity 2D Project Setup & Input
  2. 2. Player Movement, Aiming & Shooting
  3. 3. Enemy Spawning & Health System
  4. 4. Projectile Physics, Colliders & Damage
  5. 5. Debugging: Layers, Nulls & Performance

About this book

"How To Make A 2D Shooter" is a technical book by Anonymous with 5 chapters and approximately 3,892 words. Building a 2D shooter game using Unity.

This book was created using Inkfluence AI, an AI-powered book generation platform that helps authors write, design, and publish complete books. It was made with the AI Documentation Generator.

Frequently Asked Questions

What is "How To Make A 2D Shooter" about?

Building a 2D shooter game using Unity

How many chapters are in "How To Make A 2D Shooter"?

The book contains 5 chapters and approximately 3,892 words. Topics covered include Unity 2D Project Setup & Input, Player Movement, Aiming & Shooting, Enemy Spawning & Health System, Projectile Physics, Colliders & Damage, and more.

Who wrote "How To Make A 2D Shooter"?

This book was written by Anonymous and created using Inkfluence AI, an AI book generation platform that helps authors write, design, and publish books.

How can I create a similar technical book?

You can create your own technical book using Inkfluence AI. Describe your idea, choose your style, and the AI writes the full book for you. It's free to start.

Write your own technical book with AI

Describe your idea and Inkfluence writes the whole thing. Free to start.

Start writing

Created with Inkfluence AI