Skip to content
Naoya Tech
Go back

Math for Game Development: Building a 2D Shooter with High School Math

21:57 Programming & CS

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

Chapters

概要

この動画では、2Dシューティングゲームを題材に、ゲーム開発で使う数学を紹介します。プレイヤーの移動や敵の狙い、当たり判定、敵の視界、HPバー、ボスの行動まで、画面に映るものはすべて学校で習う6つの考え方だけで作れ、微分積分は1つも出てきません。

計算そのものはコンピューターがやるので、暗算が速い必要はありません。自分で決めるのは、欲しい動きに対してどの計算を呼ぶかだけです。

ポイント

  • 三平方の定理で求める距離を使うと、敵の接近の検知や円同士の当たり判定ができます。距離の2乗のまま比べれば、重いルートの計算を省けます。
  • ベクトルは位置と速度を表します。速度にフレームの経過時間dtをかけるとFPSに関係なく同じ速さで動き、入力を正規化すると斜め移動だけ約1.41倍速くなるよくあるバグが直ります。位置同士を引けば、追いかける向きが出ます。
  • 三角関数は角度と向きを行き来する道具です。atan2でプレイヤーを狙う弾を撃ち、角度を15°ずつずらせば拡散弾になり、時間をsinに渡せばアイテムがふわふわ浮きます。
  • 単位ベクトル同士の内積は、間の角度のcosになります。前後の判定や60°の視界の判定を軽い計算で行えます。
  • Lerp(線形補間)でHPバーや被弾のフラッシュを滑らかに変え、スムーズステップで緩急をつけます。ボスの行動はブール論理とステートマシンで整理します。

チャプター

Watch on YouTube

Share this post on:

Previous Video
The History of URLs: Who Decided on //, # and &?
Next Video
Step Away from the Computer: Rich Hickey's Hammock Driven Development