Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, VoroneTZ, 1 invisible), 1,512 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
c_trace: can it be wrong? #153296
09/10/07 20:21
09/10/07 20:21
Joined: Jan 2007
Posts: 110
USA East Coast
K
KojaK Offline OP
Member
KojaK  Offline OP
Member
K

Joined: Jan 2007
Posts: 110
USA East Coast
See, I've developed this pathfinding system where the player is always the end of the path, and each node has it's own action that makes it calculate a path.
The whole idea revolves around one chart, a point of view chart, a multidemensional array, that tells what nodes can see what. I create this chart 4 frames after the level has been loaded, to ensure that the nodes have registerd themselves into an array full of handles. To generate this PoV chart, I first make the function wait untill the number of nodes ready is equal to the number of nodes that exist. I then set the first node in the array to me, and then the second to you. I do a trace, ignoring all models, and if the result is 0, then there is a path, so i fill it with 1. If it is anything else than 0, there must be something in the way, so I fill it with 0. Now 1 means a path, and 0 means no path. I repeat this untill the last node has done a trace with the node before it.
However, there is a problem. I have a level where I have used this idea, but I am getting strange results. I have three nodes in a line. The nodes on either side can see eachother, but the node in the middle can't see anything!

Is there anything that can affect c_trace, or make it produce a wrong answer? I will preform more experiments, but for now, I can't think of anything that would be the problem!

I will post the whole code tomorrow. I did not have it with me today.


Lead programmer for Two Screws Loose Click here for our forums, and downloads for our games
Re: c_trace: can it be wrong? [Re: KojaK] #153297
09/10/07 21:59
09/10/07 21:59
Joined: Jul 2005
Posts: 1,002
Trier, Deutschland
Nowherebrain Offline
Serious User
Nowherebrain  Offline
Serious User

Joined: Jul 2005
Posts: 1,002
Trier, Deutschland
"me" and "you" are usually models....ignore_models, should probably not be on. Also, are you tracing between models.x?...some of my models center is at their very base, so even the smallest hill, step, or block will be in the way.


Everybody Poops.
here are some tutorials I made.
http://www.acknexturk.com/blender/
Re: c_trace: can it be wrong? [Re: Nowherebrain] #153298
09/11/07 19:37
09/11/07 19:37
Joined: Jan 2007
Posts: 110
USA East Coast
K
KojaK Offline OP
Member
KojaK  Offline OP
Member
K

Joined: Jan 2007
Posts: 110
USA East Coast
Ah, I just looked at the code, and I put on IGNORE_ME and IGNORE_YOU, so that the nodes wouldn't be detected, and models would be, so that enemies can't walk through tables...

Also, I will check the origin of my node model. You could be right!

Last edited by KojaK; 09/11/07 19:37.

Lead programmer for Two Screws Loose Click here for our forums, and downloads for our games
Re: c_trace: can it be wrong? [Re: KojaK] #153299
09/12/07 19:38
09/12/07 19:38
Joined: Jan 2007
Posts: 110
USA East Coast
K
KojaK Offline OP
Member
KojaK  Offline OP
Member
K

Joined: Jan 2007
Posts: 110
USA East Coast
Here is the code. This is all the code that does everything. There is no extra code, except the code that initiates this(it just calls the pathfind_graph_connections function), which is called 4 frames after the level is loaded. There is a 13 wait time between when you click on the level you want, and the game starting. When you first click on what you want, the level loads, does the pathfind setup, and then however much time is left just runs. The panel that covers the screen clears, and the zombies start spawning.

Please excuse all the misteaks and errors, I'm really just trying to save myself time by commenting out stuff, instead of deleting it. There are loads of lines here that actually have been commented out because they were replaced by better, faster code, and were never deleted. (RegisterMe(), for example, was from a previous attempt at pathfinding.)

Oh, and parenthandle has already been defined as skill47 or something.

Code:
 //DEFINES
define pathfind_max_nodes, 250;
define connections, skill99;

define IDno, skill97;
define pathfind_set, skill96;
define generation, skill95;
define spawn_wait_time, skill94;
define pathfind_stair, skill93;
define pathfind_zomb_pan, skill92;

define pathfind_in_my_way, flag8;
define notclose, flag7;

//Global Variables
var pathfind_node_array[pathfind_max_nodes];
var pathfind_PoV_chart[62500];
//var pathfind_path_chart[62500];//max nodes * max nodes
//var pathfind_magnitude_chart[pathfind_max_nodes];
var pathfind_next_node = -1;
var pathfind_node_number = 0;
var pathfind_ready_nodes = 0;
//entity* pathfind_counter_ent;
//entity* pathfind_counter2_ent;

var pathfind_graph_set; //true or false, tells weather the graph has been set or not

//--------------------------------NODE BASED FUNCTIONS---------------------------------
function pathfind_register_node(handleID){
pathfind_next_node += 1;
pathfind_node_number += 1;
pathfind_node_array[pathfind_next_node] = handleID;
return(pathfind_next_node);
}

function pathfind_regulate_paths(){
wait(1);
}

function pathfind_graph_connections(){
//var current_node = 0;
//var counter = 0;
//var counter2 = 0;
//var traceresult = 0;
while(pathfind_ready_nodes < pathfind_node_number){
wait(1);
}
temp.x = 0;
temp.y = 0;
while(temp.x < pathfind_node_number){
me = ptr_for_handle(pathfind_node_array[temp.x]);
while(temp.y < pathfind_node_number){
if(temp.x != temp.y){
you = ptr_for_handle(pathfind_node_array[temp.y]);
temp.z = c_trace(my.x, you.x, IGNORE_ME | IGNORE_YOU | IGNORE_MODELS);
you = ptr_for_handle(pathfind_node_array[temp.y]);
if(temp.z == 0){
you.connections += 1;
pathfind_PoV_chart[temp.x*pathfind_max_nodes+temp.y] = 1;
//if(my.z != you.z){
// my.pathfind_stair = 0;
//}
//else{
// my.pathfind_stair = -5;
//}
}
else{
pathfind_PoV_chart[temp.x*pathfind_max_nodes+temp.y] = 0;
}
}
temp.y += 1;
wait(1);
//beep();
if(you == null){
break;
}
}
temp.x += 1;
temp.y = 0;
wait(1);
if(me == null){
break;
}
}
pathfind_graph_set = true;
}

//--------------------------------ZOMBIE PATHFIND CODE
function pathfind_zombie_act_event(){
if(event_type == event_scan){
if(you.what_i_am == profgrenade){
my.health = 0;
}
}
if(event_type == event_entity){
if(my.pathfind_in_my_way == off){
//my.force_y = (random(2)-1)*1.5;
//my.pan += random(30)-15;
//my.generation = handle(you);
//my.pan = my.pathfind_zomb_pan;
//my.pathfind_in_my_way = on;
wait(1);
}
if(you.what_i_am == profzombie){
you.attacked = on;
}
}
}

action pathfind_zombie_act
{
var oldvec[3];
my.enable_scan = on;
//my.enable_entity = on;
my.event = pathfind_zombie_act_event;
//RegisterMe();
//you = player;
my.pathfind_in_my_way = off;
my.push = 3;
my.health = max_health;
my.what_i_am = profzombie;
//my.enable_shoot = on;
my.enable_impact = on;
my.alpha = 100;
my.enable_entity = on;
//my.event = zombie_shot;
you = ent_create(zombieleft, my.x, zombie_left);
my.partlarm = handle(you);
you = ent_create(zombieright, my.x, zombie_right);
my.partrarm = handle(you);
you = ent_create(zombiehead, my.x, zombie_head);
my.parthead = handle(you);
random_ehh();
while(my.health > 0){
you = ptr_for_handle(my.partlarm);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
you.tilt = my.tilt;
vec_set(you.x, my.x);
}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 310);
effect(FXGore01_BloodSpray,1,temp,vector(1,0,0));
}
you = ptr_for_handle(my.partrarm);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
you.tilt = my.tilt;
vec_set(you.x, my.x);
}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 309);
effect(FXGore01_BloodSpray,1,temp,vector(-1,0,0));
}
if(esc_menu_up == false){
if(my.attacked == on){
my.health -= 10;
if(my.control == on){
effect(FXGore01_BloodSpray,1,vector(my.x, my.y, my.z + 25),vector(0,0,2));
}
my.control = (my.control == off);
}
you = ptr_for_handle(my.parthead);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
//vec_set(temp,player.x);
//vec_sub(temp,you.x);
//vec_to_angle(you.pan,temp);
you.tilt = my.tilt;
vec_set(you.x, my.x);

}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 311);
effect(FXGore01_BloodSpray,1,temp,vector(0,0,2));
}
//START PATHFINDING CODE
//you = ptr_for_handle(my.parenthandle);
//if(you != null){
// if(you.generation < 3){ //this is for the scanning for the player
you = player;
temp.x = c_trace(vector(my.x, my.y, my.z-40), player.x, IGNORE_PASSENTS | IGNORE_PUSH | IGNORE_SPRITES | IGNORE_ME | IGNORE_YOU);
// }
// this is for testing weather you can see the node or not...
//temp.x = c_trace(vector(my.x, my.y, my.z - 40), you.x, IGNORE_PUSH | IGNORE_SPRITES | IGNORE_PASSENTS);
//}
you = ptr_for_handle(my.parenthandle);
if(temp.x == 0){
you = player;
player.shot = true;
}
if(you != null){
/*
if(you.what_i_am == profzombie){
my.pathfind_in_my_way = on;
my.pan += (random(30)-15)*2;
my.generation = handle(you);
}
temp.y = handle(you);
if(handle(my.parenthandle) == temp.y){
my.pathfind_in_my_way == off;
}
*/
//you = ptr_for_handle(my.parenthandle);
//if(my.pathfind_in_my_way == off){
vec_set(temp,you.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
my.tilt = 0;
//}
if(vec_dist(my.x, you.x) < 20){
my.parenthandle = you.parenthandle;
}
}

//END PATHFINDING CODE
//my.pan = my.pathfind_zomb_pan;
temp.x=0;temp.y=0;temp.z=0;
//you = ptr_for_handle(my.parenthandle);
//if(you != null){
/*
you = ptr_for_handle(my.generation);
if(you != null){
if(vec_dist(you.x, my.x) > 20){
my.force_y = 0;
my.pathfind_in_my_way = off;
}
}
*/
if(c_move(me, vector(1,0,0), vector(0,0,-.1), GLIDE | IGNORE_ME | IGNORE_PUSH) > 0){
ent_animate(me, "creep", my.animationpercent, anm_cycle);
my.animationpercent += 1;
you = ptr_for_handle(my.parthead);
if(you!=null){
you.attacking = false;
}
you = ptr_for_handle(my.partlarm);
if(you!=null){
you.attacking = false;
}
you = ptr_for_handle(my.partrarm);
if(you!=null){
you.attacking = false;
}
}
else{
ent_animate(me, "attack", my.animationpercent, anm_cycle);
my.animationpercent += 1;
you = ptr_for_handle(my.parthead);
if(you!=null){
you.attacking = true;
}
you = ptr_for_handle(my.partlarm);
if(you!=null){
you.attacking = true;
}
you = ptr_for_handle(my.partrarm);
if(you!=null){
you.attacking = true;
}
}
//}

}
you = null;
wait(1);
}
you = ptr_for_handle(my.parthead);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
you = ptr_for_handle(my.partlarm);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
you = ptr_for_handle(my.partrarm);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
zombie_numb -= 1;
my.event = null;
my.animationpercent = 0;
kills += 1;
ent_playsound(me, zombiedie, 200);
if(my.attacked == off){
while(my.animationpercent < 100){
if(esc_menu_up == false){
ent_animate(me, "dieA", my.animationpercent, null);
my.animationpercent += 1;
if(my.animationpercent == 50){
c_updatehull(me, my.animationpercent);
}
if(my.animationpercent == 90){
c_updatehull(me, my.animationpercent);
}
}
wait(1);
}
}
else{
while(my.animationpercent < 100){
if(esc_menu_up == false){
ent_animate(me, "dieB", my.animationpercent, null);
my.animationpercent += 1;
if(my.animationpercent == 60){
c_updatehull(me, my.animationpercent);
}
}
wait(1);
}
}

my.transparent = on;
my.passable = on;
while(my.alpha > 0){
my.alpha -= 1;
wait(1);
}
ent_remove(me);
}
//--------------------------------ALL IMPORTANT NODE ACTION----------------------------

action pathfind_node{
my.IDno = pathfind_register_node(handle(me));
my.transparent = on;
my.alpha = 50;
my.pathfind_set = false;
my.push = 4;
my.connections = 0;
my.spawn_wait_time = 0;
while(c_move(me, nullvector, vector(0,0,-2), null) > 0){
wait(1);
}
pathfind_ready_nodes += 1;
my.passable = on;
while(pathfind_graph_set == false){
wait(1);
}
while(player == null){
wait(1);
}
my.generation = 3;//5;
while(1){
temp.x = 0;
//my.alpha = 25;
temp.y = 1;
if(my.generation < 4){
temp.y = c_trace(my.x, vector(player.x, player.y, player.z - 0), IGNORE_SPRITES | IGNORE_MODELS);//IGNORE_PUSH | IGNORE_PASSENTS | IGNORE_ME);//ignore models
}
if((temp.y == 0) &&(my.pathfind_set == false)){
my.generation = 1;
my.parenthandle = handle(player);
//my.pathfind_set = true;
temp.x = 0;
while(temp.x < pathfind_node_number){
if(temp.x != my.IDno){
if(pathfind_PoV_chart[my.IDno*pathfind_max_nodes+temp.x] == 1){
temp.z = pathfind_node_array[temp.x];
you = ptr_for_handle(temp.z);
//if(you.generation == 1){
// my.animation = vec_dist(you.x, player.x);
// if(vec_dist(my.x, player.x) >= my.animation){
// my.notclose = false;
// you.notclose = true;
// you.generation = 2;
// }
//}
if((you.generation > 1) && (you.pathfind_set == false)){
you.parenthandle = handle(me);
//my.alpha = 100;
you.alpha = 100;
you.generation = 2;//my.generation + 1;
you.pathfind_set = true;
you.notclose = false;
}
}
}
temp.x += 1;
}
my.pathfind_set = false;
//my.alpha = 25;
}
temp.x = 0;
else{
if((my.pathfind_set == true) && (my.generation <= 5)){
my.notclose = false;
while(temp.x < pathfind_node_number){
you = ptr_for_handle(my.parenthandle);
if((temp.x != my.IDno) && (temp.x != you.IDno)){
if(pathfind_PoV_chart[my.IDno*pathfind_max_nodes+temp.x] == 1){
temp.z = pathfind_node_array[temp.x];
you = ptr_for_handle(temp.z);
if((you.generation > my.generation) && (you.pathfind_set != true)){
you.parenthandle = handle(me);
you.generation = my.generation + 1;
you.pathfind_set = true;
you.alpha = 100;
}
}
}
temp.x += 1;
}
if((my.generation > 1) && (my.generation <= 5) && (my.spawn_wait_time <= 0) && (zombie_numb < 20)){
you = ent_create(zombie_mdl, my.x, pathfind_zombie_act);
wait(1);
you.parenthandle = my.parenthandle;
my.spawn_wait_time = random(100)+100;
zombie_numb += 1;
}
else{
my.spawn_wait_time -= 1;
}
my.pathfind_set = false;
//my.alpha = 25;
}
}
if(my.generation >= 4){
my.alpha = 0;
}
wait(1);
my.health = 1;
}
}



Last edited by KojaK; 09/12/07 19:45.

Lead programmer for Two Screws Loose Click here for our forums, and downloads for our games
Re: c_trace: can it be wrong? [Re: KojaK] #153300
09/13/07 20:57
09/13/07 20:57
Joined: Jan 2007
Posts: 110
USA East Coast
K
KojaK Offline OP
Member
KojaK  Offline OP
Member
K

Joined: Jan 2007
Posts: 110
USA East Coast
Ahh... Interestingly enough, I have found that the nodes in a line can see eachother. It's just that when you start out(lets assume node 2 can see you, and node 1 is on your right, and node 3 on your left), they walk from 1 to 3, to 2. It's just that node 2 set node 3 before node 2. If I walk up so that they can see me, it fixes itself. However, I still have a problem with one node behind the player, where it says it can't see anything. This, I know, because when I move tward it, both nodes can see me, but when I move so that they cannot, the middle node does not tell them what to do.

Most of the problems with the paths can be solved using the c_trace in the zombie action. That tells the zombie if it can see the player, go tward the player. However, no matter what parameters I try, it either returns something other than 0, or you is being prematurely set to the zombies' parenthandle. Since no code interrupts those two sets, it has to be the trace.

If you could please tell me why the trace does not work, I would be so grateful. I have been perfecting this code for weeks now.

Thanks a lot,
KojaK


Lead programmer for Two Screws Loose Click here for our forums, and downloads for our games

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

Gamestudio download | chip programmers | 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