Matthew M Langer
  Game and Level Designer
  • Home
  • Professional Work
    • Days Gone - Main Game
    • Days Gone - Dead Don't Ride DLC
    • UntitledArenaGame
  • Older Work
    • Solo Projects >
      • Face-Off at the Frozen Throne
      • Spaceport Defense
      • Crystal Mines: Thesis Artifact
      • Phantasmagoria: Gears of War Level
    • Team Projects >
      • From The Ashes
      • Identity
      • Skyscrappers
      • Ethereality
    • Scripting >
      • Blueprint Scripting: A.I. Instructor in From The Ashes
      • Entity Scripting: Boss Battle in Crystal Mines
      • Entity Scripting: Custom Gibs in Crystal Mines
      • Entity Scripting: Melee and Ranged Combat in Crystal Mines
      • Kismet Scripting: Contextual Interaction in Phantasmagoria
      • Kismet Scripting: Stun Gun in Phantasmagoria
      • Lua Scripting: Bat A.I. in Ethereality
  • Resume

Lua Scripting: Bat A.I.

Picture
Design Goal: Create a unique and memorable enemy that is difficult enough to create a lasting challenge while having a simple attack pattern that can be countered.
Picture
Description: Since one of my strengths is pure mathematics, I decided on a bat that would have no collision with the environment, allowing its behavior to be entirely controlled by discrete mathematical functions.  I created two phases for it: Circling and Charging.  The circling phase involves the bat flying around the player including major and minor circular motion.  The charging phase involves the bat accelerating linearly towards the player.
Picture
Picture
The Compound Interest formula.  For my purposes...
P is the bat's initial position upon charging
A is the player's position at the time of the bat starting the charge
e is a constant ~= 2.718
r is the rate at which the bat's speed increases
t is the time it takes the bat to reach the player's position

Picture
With the charging phase completed, the more difficult circling phase was next.  I wanted to ensure that as a level designer, I would have a lot of flexibility in quantitatively balancing the bats motion to feel just right.  Thus, I made sure that my script would have multiple variables exposed; more than I ended up actually tweaking.
Because of how mathematically intense this script is, I decided to craft it completely at an abstract level before even attempting code implementation.  To ensure that my math was working, I used WolframAlpha to visualize my equations before moving forward with the A.I.
Picture
Picture














Visualization of one possible outcome of the final bat equation.  This represents the in-game flight pattern of the bat, assuming the player is standing still at the origin.

Picture
Design Challenge: To get a smooth looking flight pattern, I had to refresh myself on how to mathematically model circular motion and I had to integrate the velocity function x'(t) to get the position function x(t).  Additionally, taking the pure math into code is not without its own difficulties and required being cognizant of the effects of converting continuous math (Calculus) into discrete math (dt updating).