void ent_pathfinder()
{
entPathfinder = my;
ent_setState(my, STATE_IDLE);
ent_setPath(my, NULL);
my->flags &= ~PASSABLE;
path_set(my, "path_000");
VECTOR vec_to_target;
while (1)
{
if (ent_getState(my) == STATE_FOLLOW_PATH)
{
ent_drawPath(my, vector(0, 255, 0)); // display path
LL_PFIND_PATH_NODE *node = ent_getFirstPathNode(my);
if (node) // path is not empty
{
VECTOR vec_to_node;
VECTOR *node_pos = ll_pfind_getPathNodePos(node);
var dist = vec_dist(&my->x, node_pos);
//vec_diff(&vec_to_node, node_pos, &my->x);
//vec_to_angle(&my->pan, &vec_to_node);
// vec_add(&my->x, &vec_to_node);
vec_diff(&vec_to_target, &node->pos, &my->x);
vec_to_angle(&my->pan, &vec_to_target);
my->tilt=0;
vec_normalize(&vec_to_target, minv(dist, PATHFINDER_SPEED * time_step));
c_move(my, vector(10 * time_step, 0, -1), nullvector, GLIDE);
if (dist < 10) // node reached
{
ll_pfind_stringPullingFirst(my, ent_getPath(my), 3, ent_isReachable);
ent_removeFirstPathNode(my);
}
}
else // end of path reached
{
ent_setState(my, STATE_IDLE);
ent_setPath(my, NULL);
}
}
wait(1);
}
}