A Simple Enemy?

I’ve been trying to make a really simple enemy by following tutorials and trying to get it to work for what I’m doing, but I’m having a hard time, just because I don’t know where to start.

I basically want to make an enemy that does this:

  1. chases the player when the player gets too close
  2. causes damage when colliding with the player (I can do this part of the code myself)
  3. stops chase once the player outruns the enemy and gets a certain distance away.

If anyone can help me understand how to make these enemies, or lay down some code for me, that would be great.

If you need the player script, here’s a portion of it that would be most relevant.

PlayerStatus.js

var health : float;
var points : float;


function Update () {
}


function ApplyDamage (totalDamage : int) {
	health -= totalDamage;
	if (health <= 0) {
		Kill ();
	}
}

function Kill () {
	print("YOU ARE DEAD");
}

How is your enemy moving? Does it have to turn to move in a new direction or is it more arcade-like where it can move in any direction without turning?

It doesn’t really have to face any specific direction. It’s more arcade-like. It’s just going to be a simple ball collider, probably with some particle effects on it, so it doesn’t have to face anything. It can, but it’s not necessary.