Notes from the KAYAC hyper-casual team
Tag: Math (13)

I Tried Making a Confetti Effect with Physics Simulation
A confetti effect in Unity built from point-mass physics: each scrap of paper is two point masses with Verlet integration, air resistance along slightly bent normals and a quaternion for orientation, drawn in bulk with skinning-based pseudo-instancing and a small color atlas.

Trackball-Style Camera Control Using Quaternions
A camera you rotate by dragging a trackball-like sphere, built in Unity with quaternions: integrating angular velocity, turning drags into angular velocity with a cross product, inertia, and what quaternions are good for.

Quietly Dangerous - On the Precision of Shader Variables
How floating-point precision works and why using half for UVs and positions in a shader causes bugs that appear only at high resolutions and only on some devices, with a few related pitfalls.

I Don't Get B-Spline Curves at All
An intuitive explanation of quadratic B-spline curves as blending three neighboring points with blend functions of width 3, with a JavaScript implementation, handling of the ends and loops, and the references used.

Height-Dependent Fog - Getting That "Gas Pooling in the Low Ground" Look
Building a fog that thins out with height in a Unity shader: from basic exponential fog, through a fog that ends at a fixed height, to a fog whose density falls off exponentially with height, derived by integration.

I Love the Log-Normal Distribution
An easygoing introduction to the log-normal distribution: how it differs from the uniform and normal distributions, how to generate it in code, where it shows up in money and society, and how it can be used in games, from random tap tests to dummy user data and damage design.

I Want to Fit Things on Screen Just Right in a 3D Game! Automatically!
How to compute a camera position, with direction and field of view fixed, so that a set of points in 3D space just fits on screen, worked out first in 2D and then turned into Unity code.

Rotating a Vector in 3D Space
How to scatter beams in a cone around an axis in Unity: with a Transform, by converting a local vector to world space, and without one, by building a RotateVector function from projection, dot and cross products.

I Want to Scatter Points Randomly on a Circle or a Sphere - Building Distribution Functions with High School Math
How to scatter points uniformly on a disk, a sphere and a hemisphere, and how to bias them toward the pole with a tunable parameter, by building a cumulative distribution function with high school calculus and inverting it.

Homing Calculations for Beams and Missiles
How the beams in a particle demo home in on their target: the common ways to steer toward an enemy, and the method used here, which bends the velocity with a capped centripetal acceleration and keeps the speed constant with propulsion and damping.

What I Wondered About When I Wanted to Use Random Numbers from Threads in Unity
A comparison of random number generators that can be used from threads in Unity (System.Random, MWC, XorShift, and the XorShift128 said to be inside UnityEngine.Random): their speed, their randomness as images and in the gorilla test, and their memory use.

Animation Made with Interpolation Functions
The basics of making animation in code: linear, quadratic and cubic interpolation, exponential interpolation computed step by step, and a spring-damper, with how each one moves and how to keep it from blowing up.

Making Effects That Travel Between the 2D and 3D Worlds in Unity
How to send effects between characters in a 3D world and 2D UI drawn by a separate camera in Unity: placing 3D effects at a UI element's position, and drawing 2D effects that look as if they move in 3D, with the vector math.