AI for Enemies

As I put the finishing touches on my AI script for the two enemies in our new title, Cosmotic Blast, I wanted to out line some of what went into the design.

Enemies Movement

Enemies had to head towards you, close the gap but also not run into you. So I used this equation to find a point / vector in space to set as a target.

Vector3 locationTarget = ((target.transform.position - transform.position) + (transform.position - target.transform.position).normalized * distance);

Saying that equation in english: Take the targets position and subtract enemies position to get a vector from enemy to target. Now add back a vector from the target to the enemy but only at a given distance. See how that makes a point in space at distance from the target. If you’re to close, it could be behind you.

To avoid targets, I found all near by objects with a OverlapShereNonAlloc() with a given distance. Then applied a opposing force to the enemy. So in a loop …

force += (transform.position - nearByObjects[i].transform.position).normalized * speed;

The speed is a variable since some enemies art faster at avoiding things than others. This also makes it avoid other enemies so they fly around with a nice spacing.

I can also reverse this force for Upgrade objects so the enemy takes them for their self. Muhahah!

Enemies Shoot!

First things first, you got to aim at your target:

Vector3 pos = target.transform.position - transform.position;
Quaternion rot = Quaternion.LookRotation(pos);
transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime * speed);

Why Lerp? Lerp makes it so it slowly rotates towards a target at a given speed. The speed is based on what level the enemy is at.

Next, got to shoot. Well this is more complex, because it depends on what the enemy is shooting but to start it off, I do a Physics.Raycast and find if the “Player” is in front of the enemies canon … then I fire().

if (physics.Raycast (transform.position, canon.gameObject.transform.forward, out hit, range, rayMask)) {
    if (hit.transform.tar == "") {
        Fire();
    }
}

The rayMask hides the Raycast from different gameObjects.

All the rest

All the rest is inherited from the classes that the ship uses, like upgrades and shield, etc.

Fun fun happy times.

Engineering Bay

People ask, what are you working on? What more do you have to develop for The Cosmotic Mission to get it to v1.0? Of course I tell them content and that means levels and game obstacles but that also means completing the ship.

Third Bay Blind: What is that other area in the ship? Engineering bay!

Ever wonder what the other button was for? Did you see that the ship had three bays?

The main bay is the Commanding bay, where you navigate the cosmos, launch the drone and tally up your score.

Version 0.6.1 introduced the second bay, the Living Quarters, an area to play around with collectables, see where you live, and reset the game.

It’s time for the Engineering Bay

*Beep*boop* I has buttons

The game functionality of the engineering bay is simple, credits. I know, not exactly what gamers are pining to get access to but I need to give credit where credit is due. I had so much support from my Kickstarter and friends and family. I want to recognize them. Also there are tools and plug-ins that I need to credit. Joy.

In game, this is where you get access to the heart of the ship – this intergalactic magnetic-cosmotic-energy space-time warping high tech modern wonder.

Design & Sketch

Here are examples of the Living Quarters, sketch to final.

The Engineering scene is very simple in regards to game overhead, no grabbing obstacles, no collision, no added functionality so I have a lot of room for mesh detail. I hope to flex my modeling skills here.

The commanders bay hinted of the engineering bay with three tubes leading off to the left. This room will have the first cosmotic crystal discovered by humans wired up so we can take advantage of its mysterious powers.

There will be tubes and glowing crystal with large gears that look like they could drive the three spinning rings. Rubber and metal are the predominant materials. Digital panels will display titles and names to satisfy the credit criteria.

Stay tuned …

This is where I am today. I’m going to play in modo and block some shapes to get a better feel of the space.