Report RSS On Avaruustaistelupeli (devlog #19)

Posted by on

Last two weeks I’ve been mostly fixing bugs and making improvements to AI; a slow job and particularly difficult to debug and test. As I’ve probably mentioned before, my final goal is to implement a set of clearly distinct AI opponents with individual skills and combat styles.

As a starting point, I usually try to implement as perfect AI as possible. In this case it requires a complex observation system, hit detection and prediction of accelerating projectiles. In other words, lots of trigonometry and somewhat higher math. Not one of my strengths. Downgrading the AI is easier: just apply random inaccuracy to shooting and other activities. Previously the inaccuracy was just a random offset to the aim position, amount of randomness depending on target distance and AI skill. This worked with projectiles, but it made beams (cutter, tractor and pressor) jumping around recklessly. Therefore even poor AI has so far aimed beams perfectly.

In order to fix this and achieve smoothness, I switched the common random to perlin-noise. The following Unity code generates a gradual movement inside a circle as shown in the image below it. Statistically the distribution isn’t quite even, but close enough.

public static Vector2 PerlinInsideCircle(Vector2 pCenter, float pRadius, float pTime) {
    float x = Mathf.PerlinNoise(pTime, 0f) * 2f - 1f;
    float y = Mathf.PerlinNoise(0f, pTime) * 2f - 1f;
    var offset = Vector2.ClampMagnitude(new Vector2(x, y), 1f) * pRadius;
    return pCenter + offset;
}

19 perlin2

Adding this to the perfect aim makes the crosshair movement smooth, and it can be used with any AI level. Below are examples of an accurate AI (yellow) and a very inaccurate one (red).

19 inaccuracy big

In order to make the AI opponents more diverse, I’ve parameterized pretty much every aspect of the behavior. These give me tons of possibilities to determine the skills and style of the opponent, but I am yet to pick the most significant ones and balance them properly.

19 characteristics

I also improved the component that observes the battlefield. For instance, the AI now uses the close and ranged combat power of its enemies to decide its actions. No longer should AIs do stupidities such as close combat with missiles against laser cutters and cannons. But as I mentioned earlier, it is a slow job and particularly difficult to debug and test. So they probably will.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: