0 registered members (),
18,435
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: enemy's path:HELP!
[Re: bart_the_13th]
#348663
11/29/10 05:29
11/29/10 05:29
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
hi again! i have downloaded a file that will follow the enemy without using a crumb, the player is followed by his distance to the zombie. here is the code:
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
function main()
{
video_set(800,600,32,0);
fps_max = 60;
level_load("level.WMB");
wait(3);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
VECTOR dist;
VECTOR absdist;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
#define health skill1
#define state skill2
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
SOUND* p_death = "p_death.wav";
SOUND* p_pain = "p_pain.wav";
SOUND* z_alert = "z_alert.wav";
SOUND* z_attack = "z_attack.wav";
SOUND* z_death = "z_death.wav";
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
function handle_camera()
{
camera.genius = my; //camera position
camera.arc = 80;
vec_set(camera.x,vector(my.x,my.y,my.z+30));
my.pan = camera.pan;
camera.pan -= 10 * mouse_force.x * time_step;
camera.tilt += 10 * mouse_force.y * time_step;
camera.tilt = clamp(camera.tilt,-90,90);
}
function handle_movement()
{
if(key_shift) //using wasd keys for movement
{
dist.x = 15 * (key_w - key_s) * time_step;
dist.y = 15 * (key_a - key_d) * time_step;
}
else
{
dist.x = 10 * (key_w - key_s) * time_step;
dist.y = 10 * (key_a - key_d) * time_step;
}
}
function handle_gravity()
{
result = c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX);
if(result > 5)
{
absdist.z -= 2 * time_step;
}
else
{
absdist.z = 0;
}
}
action hero()
{
player = my;
my.eflags |= FAT | NARROW;
wait(1);
vec_set(my.min_x,vector(-20,-20,-40));
vec_set(my.max_x,vector(20,20,40));
my.health = 100;
while(my.health > 0) // while I'm alive
{
handle_gravity();
handle_movement();
c_move(my,dist,absdist,IGNORE_PASSABLE|GLIDE);
handle_camera();
wait(1);
}
set(my,PASSABLE);
vec_set(camera.x,vector(my.x,my.y,my.z-20));
snd_play(p_death,70,0);
wait(-0.5);
error("YOU ARE DEAD!!!");
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
action zombie()
{
VECTOR zdist;
VECTOR zabsdist;
VECTOR temp;
VECTOR p;
VECTOR p2;
var hand_palm = 346;
var hand_top = 338;
var alert_snd = 1;
var pain_snd = 0;
var attack_snd = 0;
my.eflags |= FAT | NARROW;
wait(1);
vec_set(my.min_x,vector(-20,-20,-40));
vec_set(my.max_x,vector(20,20,40));
my.health = 100;
my.state = 0; // waiting for player
while(my.health > 0)
{
if(my.state == 0)
{
ent_animate(my,"stand",my.skill60,ANM_CYCLE);
my.skill60 += 2 * time_step;
vec_set(zdist.x,nullvector);
vec_set(zabsdist.x,nullvector);
if(vec_dist(my.x,player.x) < 800 && player.health > 0) //350
{
my.state = 1;
}
}
if(my.state == 1)
{
if(alert_snd == 1)
{
snd_play(z_alert,70,0);
alert_snd = 0;
}
vec_set(temp.x,player.x);
vec_sub(temp.x,my.x);
vec_to_angle(my.pan,temp);
my.tilt = 0;
ent_animate(my,"walk",my.skill60,ANM_CYCLE);
my.skill60 += 8 * time_step;
zdist.x = 5 * time_step;
zdist.y = 0;
zdist.z = 0;
vec_set(zabsdist.x,nullvector);
if(vec_dist(my.x,player.x) > 360)
{
my.state = 0;
}
if(vec_dist(my.x,player.x) < 65)
{
my.state = 2;
}
if(player.health <= 0)
{
my.state = 0;
}
}
if(my.state == 2)
{
vec_set(temp.x,player.x);
vec_sub(temp.x,my.x);
vec_to_angle(my.pan,temp);
my.tilt = 0;
my.roll = 0;
my.skill40 = 0;
while(my.skill40 < 100)
{
vec_for_vertex(p,my,hand_palm);
vec_for_vertex(p2,my,hand_top);
if(c_trace(p,p2,IGNORE_ME | IGNORE_PASSABLE) > 0)
{
attack_snd = 1;
if(attack_snd == 1)
{
snd_play(z_attack,70,0);
attack_snd = 0;
}
if(you == player)
{
pain_snd = 1;
if(pain_snd == 1)
{
snd_play(p_pain,70,0);
pain_snd = 0;
}
you.health -= 100 * time_step;
}
}
ent_animate(my,"attack",my.skill40,NULL);
my.skill40 += 8 * time_step;
wait (1);
}
vec_set(zdist.x,nullvector);
vec_set(zabsdist.x,nullvector);
if(vec_dist(my.x,player.x) > 70)
{
my.state = 1;
}
if(player.health <= 0)
{
my.state = 0;
}
}
c_move(my,zdist,zabsdist,IGNORE_PASSABLE|GLIDE);
wait(1);
}
set(my,PASSABLE);
snd_play(z_death,70,0);
my.skill60 = 0;
while(my.skill60 < 100)
{
ent_animate(my,"deaht",my.skill60,NULL);
my.skill60 += 5 * time_step;
wait(1);
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
PANEL* gui =
{
digits(10,0,4,"Arial#24bi",1,player.skill1);
flags = SHOW;
}
my question is, how can i make the zombie move even if the player is too far from him? if i use a PATH, how will the enemy detect the nearest node?
|
|
|
Re: enemy's path:HELP!
[Re: carla_mariz]
#350447
12/16/10 03:33
12/16/10 03:33
|
Joined: Jan 2006
Posts: 245 PA
Garrettwademan
Member
|
Member
Joined: Jan 2006
Posts: 245
PA
|
Hey there....I don't know if this will help you but I have developed two functions to create your own waypoints using a datafile, and then replaying them using an on demand key. Check these out to see if this helps at all
function save_way_point(){ //When the ` is pressed, it will save player pan, x and y position for waypoints
//var old_pan = 0;
//var degree_difference = 0;
handle_position = file_open_append("waypoint.txt");
wait(1);
degree_difference = Player.pan - old_pan;
file_var_write(handle_position, player_pan);
file_var_write(handle_position, degree_difference);
file_var_write(handle_position, player_x);
file_var_write(handle_position, player_y);
file_close(handle_position);
old_pan = Player.pan;
}
function replay_waypoints(){
var old_x = 0;
var old_y = 0;
var old_pos_x = 0;
var old_pos_y = 0;
var difference_x = 0;
var difference_y = 0;
var absolute_pan = 0;
var counter = 0;
var border_x = 0;
var border_y = 0;
var time_counter = 0;
replaying = 1;
handle_position = file_open_read("waypoint.txt");
wait(1);
Player.pan = file_var_read(handle_position);
absolute_pan = file_var_read(handle_position);
Player.x = file_var_read(handle_position);
Player.y = file_var_read(handle_position);
while(1){
old_pos_x = player_x;
old_pos_y = player_y;
player_pan = file_var_read(handle_position);
if(player_pan == -361){break;}
absolute_pan = file_var_read(handle_position);
player_x = file_var_read(handle_position);
player_y = file_var_read(handle_position);
counter = 0;
while(counter <= 19){
Player.pan += absolute_pan/20;
wait(10);
counter +=1;
}
//Fail Safe Method
difference_x = old_pos_x - player_x;
if(difference_x < 0){border_x = 1;} //Number is positive
else{border_x = -1;} //Number is negative
difference_y = old_pos_y - player_y;
if(difference_y < 0){border_y = 1;} //Number is positive
else{border_y = -1;} //Number is negative
time_counter = 0;
while(vec_dist(Player.x, vector(player_x,player_y,Player.z)) > 10){
c_move(Player,vector(2,0,0),vector(0,0,0),NULL);
if(difference_x == 1){
if(Player.x >= player_x + 10){Player.x = player_x;}
}
if(difference_x == 1){
if(Player.x <= player_x - 10){Player.x = player_x;}
}
if(difference_y == 1){
if(Player.y >= player_y + 10){Player.y = player_y;}
}
if(difference_y == 1){
if(Player.y <= player_y - 10){Player.y = player_y;}
}
//Animate Player
ent_animate(Player,"walk",Player.animation,anm_cycle);
Player.animation += 0.25;
//Make sure player isn't stuck in a wall
time_counter += 1;
if(time_counter == 5){
old_x = Player.x;
old_y = Player.y;
}
if(time_counter >= 30){
if(old_x == Player.x && old_y == Player.y){
Player.x = player_x;
Player.y = player_y;
}
time_counter = 0;
}
wait(1);
}
wait(1);
}
file_close(handle_position);
replaying = 0;
}
|
|
|
|