|
Changing entity target or my during runtime
#186315
02/28/08 18:57
02/28/08 18:57
|
Joined: Feb 2007
Posts: 146 UK
robertbruce
OP
Member
|
OP
Member
Joined: Feb 2007
Posts: 146
UK
|
Hello,
I am working on a fps and would like to know if it is possible to change an entity target using vec_dist during run time.
I am trying to create a code that allows a model to move to different entities during the game. Once it has reached the chosen entity, they wait and move to the next entity. Once the last entity has been reached, the model will go back to the first entity and the process starts again.
The code below does not work and I understand it may be because I am using a var to change the entity target when using vec_dist. Do I use handles and if so, how?
I have placed 5 entites in a level with actions entity_marker01 to entity_marker05 along with a model assigned move_model. (and a camera position to look at the level)
There are probably other ways to achieve this, but could anyone tell me if it is possible changing the target using vec_dist?
/////////////////////////////////////
entity* marker_01; entity* marker_02; entity* marker_03; entity* marker_04; entity* marker_05;
DEFINE move_x,skill23;
var entity_choice=1; var chosen_entity=1; var ent_timer=20;
function change_entity() { if (entity_choice==1) { chosen_entity = marker_01; } if (entity_choice==2) { chosen_entity = marker_02; } if (entity_choice==3) { chosen_entity = marker_03; } if (entity_choice==4) { chosen_entity = marker_04; } if (entity_choice==5) { chosen_entity = marker_05; } }
action entity_marker01 { marker_01 = my; }
action entity_marker02 { marker_02 = my; }
action entity_marker03 { marker_03 = my; }
action entity_marker04 { marker_04 = my; }
action entity_marker05 { marker_05 = my; }
action move_model {
while (1) {
if(vec_dist(my.x,chosen_entity.x)>10)//if not closer than 10 // how do I change this entity target { vec_set(temp, chosen_entity.x); //how do I change this entity target? vec_sub(temp, my.x); vec_to_angle(my.pan, temp); c_move(my,vector(15*time,0,0),my.move_x,use_aabb | ignore_passable | glide);//move towards entity
}
else
{ while(ent_timer>0) { wait(1); ent_timer-= time / 16; } if(entity_choice==5) { entity_choice=1; change_entity(); } else { entity_choice+=1; change_entity(); } ent_timer=20; } } }
I could use a while(vec_dist(my.x,chosen_marker.x)<20) instead of help.
Anyway, I have spent a number of hours and would appreciate any help.
Thanks,
Rob
|
|
|
Re: Changing entity target or my during runtime
[Re: robertbruce]
#186316
03/03/08 23:51
03/03/08 23:51
|
Joined: Sep 2003
Posts: 281 Arkansas\USA
raiden
Member
|
Member
Joined: Sep 2003
Posts: 281
Arkansas\USA
|
Hi Robert, I looked at your code and wrote a script for you that is close to what you are trying to do. I haven't tested the code, so I am not sure how it will react when the target is within 10 quants. Basically what you have is 2 actions, ent_target() is for the objects in the game you want as targets, and ent_to_target() is for the entity you want to move to the targets. Let me know if you have any questions. Code:
////////////////////////////// // Target Ents //////////////////////////////
define max_ents, 5; // change this if you would like more target entities
var ent_array[max_ents]; var ent_ctr; var ent_timer = 0; // start with 0 because we need to set a target first
entity* target_ent;
action ent_target() { ent_array[ent_ctr] = handle(my); }
action ent_to_target() { var move_dist[3]; var move_speed; move_speed = 6; // change this to move faster or slower while(ent_ctr < (max_ents - 1)) { wait(1); } // wait for all entities to be stored ent_ctr = 0; // reset for further use while(1) { move_dist.x = move_speed * time_step; if(target_ent != null) { if(vec_dist(target_ent.x,my.x) > 10) { vec_to_angle(my.pan,vec_diff(temp,you.x,my.x)); c_move(me,move_dist,nullvector,use_aabb | ignore_passable | glide); } } else { while(ent_timer > 0) { ent_timer -= time_step / 16; } target_ent = ptr_for_handle[ent_array[ent_ctr]]; ent_timer = 20; // change every 20 seconds ent_ctr += 1; // change to the next target if(ent_ctr == max_ents) { ent_ctr = 0; } } wait(1); } }
-raiden
"It doesn't matter if we win or lose, it's how we make the game."-------------------- Links: 3DGS for Dummies
|
|
|
|