Mobile Artillery: Bots

With the player prefab mostly in place, I duped it and wrote a special controller script to drive it around autonomously as a bot. I sketched out an initial plan for its search and destroy behavior flow.

I gave this new prefab a big, green, cone collider attached to the end of its nose. They randomly scan around the environment “looking” for enemies. If another tank enters the collider’s trigger, the controller script then calculates the distance and angle between the two tanks.

At this stage, a human player would typically take an instinctive guess at the pitch and power for the initial shot and then adjust and tune the controls until a hit is achieved. I wanted to simulate that kind of imperfect, but adjusting behavior.

The first step was to establish what my bot’s first instinctive guess should be. I setup a target at various distances and manually fired at it, recording the power used to achieve a successful hit (with a constant pitch and no wind conditions). I plotted these to a graph and then punched these values into a function equation finder. I used this equation to drive the power setting for the bot’s initial shot.

If the projectile misses (which is very likely since bots are also affected by wind!), it will determine if the shot landed too far left or too far right from the target. Then, it will adjust its facing by a random angle and repeat this sort of adjustment until it has successfully hit its target. It does a similar adjustment for its power if the shot lands in front of or behind its target.

Bots spawn in at random locations. You can see two of them working reasonably well in this video. That said, this is a very simple test and if I were to continue, I’d want to account for varying elevations, occlude the bot’s visibility so it can’t see through obstacles, and introduce movement as a way of scouring the environment and evading attacks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: