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