Overview
This video introduces the math used in game development, with a 2D shooting game as the running example. Everything on screen, from player movement and enemy aiming to hit detection, enemy vision, the HP bar and boss behavior, is built from just six ideas covered in school, and calculus never comes up.
The computer does the arithmetic, so there is no need to calculate quickly. What you decide is which calculation produces the movement you want.
Key Points
- Distance from the Pythagorean theorem handles proximity checks and circle-based hit detection, and comparing squared distances skips the costly square root.
- Vectors describe position and velocity. Multiplying velocity by the frame time dt keeps speed independent of the frame rate, normalizing input fixes the classic bug where diagonal movement is about 1.41 times faster, and subtracting positions gives a homing direction.
- Trigonometry converts between angles and directions: atan2 aims a shot at the player, adding 15° steps creates a spread shot, and a sine wave over time makes items float.
- The dot product of two unit vectors is the cosine of the angle between them, a cheap way to tell front from back or to check a 60° field of view.
- Lerp smooths the HP bar and damage flash, with smoothstep for easing, while Boolean logic and a state machine keep the boss’s behavior organized.
Chapters
- 0:00 Introduction
- 0:09 The task: building a 2D shooter
- 0:23 Only six kinds of math
- 0:38 No calculus needed
- 1:03 1. Distance (Pythagorean theorem)
- 7:47 2. Vectors
- 11:13 3. Angles and trigonometry
- 14:36 4. Dot product
- 16:54 5. Lerp (linear interpolation)
- 18:57 6. Boolean logic and state machines
- 20:57 Summary
概要
この動画では、2Dシューティングゲームを題材に、ゲーム開発で使う数学を紹介します。プレイヤーの移動や敵の狙い、当たり判定、敵の視界、HPバー、ボスの行動まで、画面に映るものはすべて学校で習う6つの考え方だけで作れ、微分積分は1つも出てきません。
計算そのものはコンピューターがやるので、暗算が速い必要はありません。自分で決めるのは、欲しい動きに対してどの計算を呼ぶかだけです。
ポイント
- 三平方の定理で求める距離を使うと、敵の接近の検知や円同士の当たり判定ができます。距離の2乗のまま比べれば、重いルートの計算を省けます。
- ベクトルは位置と速度を表します。速度にフレームの経過時間dtをかけるとFPSに関係なく同じ速さで動き、入力を正規化すると斜め移動だけ約1.41倍速くなるよくあるバグが直ります。位置同士を引けば、追いかける向きが出ます。
- 三角関数は角度と向きを行き来する道具です。atan2でプレイヤーを狙う弾を撃ち、角度を15°ずつずらせば拡散弾になり、時間をsinに渡せばアイテムがふわふわ浮きます。
- 単位ベクトル同士の内積は、間の角度のcosになります。前後の判定や60°の視界の判定を軽い計算で行えます。
- Lerp(線形補間)でHPバーや被弾のフラッシュを滑らかに変え、スムーズステップで緩急をつけます。ボスの行動はブール論理とステートマシンで整理します。