Maths & Physics Playground
Mission Brief
Solve common 3D gameplay-math bugs from first principles using dot products, cross products, and subspace projection rather than black-box engine helpers.
Key Systems Engineered
Dimension-Reduced XZ-Plane Field-of-View Detection (EnemyVision.cs)
Flattens both the observer's forward vector and the direction-to-target onto the XZ plane (zeroing Y before normalizing) prior to computing the dot product against cos(viewAngle / 2). Prevents elevation differences from causing false-positive or false-negative 3D cone checks, visualized live with green/red Editor Gizmos.
Un-Normalized Cross-Product Proportional Turret Controller (TurretLogic.cs)
Computes the cross product of the flattened turret forward vector and flattened target direction, intentionally omitting normalization so the resulting Y component's magnitude scales proportionally with angular error. Acts as a natural P-controller that decelerates smoothly into alignment without bang-bang overshoot jitter.
Gracefully Self-Expanding Projectile Pool (ObjectPool.cs & PooledObject.cs)
Pre-warms inactive projectiles at Start() and dynamically instantiates and registers additional instances on the fly if sustained fire exhausts the active pool, resetting lifetime timers in OnEnable().
Implementation Details
Architecture & Deep Dive
This project solves three common 3D gameplay-math problems from first principles: field-of-view detection, smooth turret tracking, and efficient projectile management.
The FOV system flattens vectors to the XZ plane before dot-product comparison, preventing Y-axis elevation from corrupting horizontal angle checks. The turret controller uses an un-normalized cross product as a natural proportional controller — angular error directly maps to rotation speed without needing explicit PID tuning.