Well I tested your code and my enemy is facing the player and moving to him.
The only thing I had to add was a wait in the enemy code until the player was created, I only took out the animation code and particle code.
Heres the whittled down code I used
var video_mode = 7; // 800x600
var video_depth = 32; // 16 bit mode
var player_distance; // moves the player
var enemy_distance; // moves the enemy
define healthpoints = skill18; // just another name for skill18
entity* enemy; // useful only if you want to display its health
function main()
{
level_load("level.wmb");
wait (2); // wait for the level to be loaded
clip_size = 0; // show all the triangles for all the models
on_d = null; // disable the debug panel (key "D") because it is used for movement
fps_max = 40; // lock the frame rate to 40 fps
}
action player_fight // attached to the player
{
player = me; // I'm the player
player.healthpoints = 100; // and I have 100 health points
while (player.healthpoints > 0) // as long as I'm alive
{
camera.x = player.x - 200 * cos(player.pan); // 200 = distance between the player and the camera
camera.y = player.y - 200 * sin(player.pan); // same value here
camera.z = player.z + 50; // above the player
camera.pan = player.pan; // looks in the same direction with the player
camera.tilt = -10; // look down at the player
my.pan +=0 * (key_a - key_d) * time_step - 20 * mouse_force.x * time_step; // rotates with the keys A and D or with the mouse
player_distance.x = 10 * (key_w - key_s) * time_step; // moves forward / backward with W / S
player_distance.y = 5 * (key_a - key_d) * time_step; // move side to side
player_distance.z = 0;
ent_move(player_distance, nullvector);
wait (1);
}
}
action enemy_fight // attached to the enemy
{
while(player == NULL){wait(1);}
enemy = me; // I'm the enemy
enemy.healthpoints = 20; // and I have 100 healthpoints
while (my.healthpoints > 0) // as long as I'm alive
{
if (vec_dist (my.x, player.x) < 600 && player.healthpoints > 0) // the player approaches the enemy
{
vec_set(temp, player.x);
vec_sub(temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac
enemy_distance.x = 5 * time_step;
enemy_distance.y = 0;
enemy_distance.z = 0;
ent_move(enemy_distance, nullvector);
}
wait (1);
}
}
Does it still do the same thing using this code?