Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,731 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
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
C
carla_mariz Offline OP
Junior Member
carla_mariz  Offline OP
Junior Member
C

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:
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 Offline
Member
Garrettwademan  Offline
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

Code:
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;
}




Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1