Hi all, i have a problem about updating multiple entities position, as in which is ranked 1st, 2nd, or 3rd.
var position;
var distance;
var ai1_distance;
var ai2_distance;
From start point to end point, i used vec_dist to calculate the distance between the player and end point.
function decrement_position(){
if (position == 1){
position = 2;
}
else if (position == 2 || position >3){
position = 3;
}
}
function increment_position(){
if (position == 3){
position = 2;
}
else if (position ==2 || position <1){
position =1;
}
}
function update_position(){
if(ai1_distance < distance){
decrement_position();
}
else if (ai2_distance < distance){
decrement_position();
}
else{
increment_position();
}
}
while(1){
distance = vec_dist(endpoint.x, my.x);
ai1_distance = vec_dist(endpoint.x, ai1.x);
ai2_distance = vec_dist(endpoint.x, ai2.x);
update_position();
wait(1);
}
so whenever the AI passes the player, the position changes, but the problem is that the position kept increasing or decreasing when the distance is lesser than ai1_distance.
How do i call it to update the position once, but at the same time the distance needs to be kept updated?
Sorry for the ugly codes and thanks in advance. This had me troubled for quite sometime =(