Making interesting enemies that don't kill each other?

Hi, for my current project, I’m working on a shooter game in which the player is armed to the teeth against a large fleet of alien ships. Unfortunately, I’m not entirely sure what to do with the aliens. As of my last release, all they do is look at the player right when they spawn, move towards the player, and shoot at random times. The most variation on this is that two varieties of the 5 ships teleport randomly, but in the end I feel it plays about the same. Another problem I encounter is that because they all have the same target, a good portion of them crash into each other and are destroyed before they can pose a threat to the player.

Does anybody have any suggestions for what to script to make a ship more unique?

When working on a shooter I usually implement some kind of sequential scripted AI. Each type of monster follow a pattern of very simple actions, these patterns or arrays of action execute once or loop.
I use simple actions such as :

  • wait
  • moveTo
  • moveTowardPlayer
  • shootTo
  • shootTowardPlayer
  • etc…
    Each individual Alien has a ‘current’ action in his action scenario and he performs this action until it is considered ‘done’, then he passes to the next action

To make your ennemies behave not exactly the same even if they are of the same type (hence they have the same scenario), you just have to add individual random parameters for each of these actions : a duration for the wait action, a speed for the moveTo, a duration for the moveTowardPlayer, a precision factor or a dispersion for the shootTo if it shoots in spray, etc, etc.

You can come up with a lot of different simple actions that will form original and complex behaviors.

Alright, I’ve written functions for various simple tasks. How do I call these functions, though? If I use “Function Update()” the entire game will lag and the ship rams the player without even a second’s notice.

Well, AI functions should indeed be called on an Update() or at least FixedUpdate() basis. You just have to remember that everything concerning gameplay handled by Update() should be modified by Time.deltaTime since you don’t know how many time it will be called by second.

Well, I’m having trouble with something here, and I’m unsure what the problem is. The game lags as soon as the first ship is spawned, and the ship instantaneously rams the player without any visible action. Does anybody see what the problem is?

var speed = 10;
var minspeed = 2.5;
speed *= Random.value;
speed += minspeed;
var shipTarget : Transform;

function Update () {
	if (Time.timeScale > 0) {
		if (transform.position.y == 0) {
shipWait(2);
moveTo(Vector3(Random.value * 10, 0, Random.value * 10));
moveTowardPlayer(shipTarget);
fire(shipTarget);
}
	}
}

function shipWait (waitTime : float) {
	yield WaitForSeconds(Random.value * waitTime);
}

function moveTo (targetlocation : Vector3) {
	transform.LookAt(targetlocation);
	transform.position = Vector3(Mathf.Lerp(transform.position.x, targetlocation.x, speed*Time.deltaTime), 0, Mathf.Lerp(transform.position.z, targetlocation.z, speed*Time.deltaTime));
}

function moveTowardPlayer (target : Transform) {
	facePlayer(shipTarget);
	moveTo (shipTarget.position);
}

function facePlayer (target : Transform) {
		if (shipTarget) {
		// Look at and dampen the rotation
		var rotation = Quaternion.LookRotation(shipTarget.position - transform.position);
		transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime);
	}
}

function fire (shootTarget : Transform) {
	facePlayer(shootTarget);
	gameObject.SendMessage("Shoot", SendMessageOptions.DontRequireReceiver);
}