## Lua Scripting: Bat A.I.

**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.

**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**.

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

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

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.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.

**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).