2 registered members (TipmyPip, 1 invisible),
18,731
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
question about updating position
#227812
09/16/08 08:45
09/16/08 08:45
|
Joined: Aug 2008
Posts: 11
silently99
OP
Newbie
|
OP
Newbie
Joined: Aug 2008
Posts: 11
|
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 =(
|
|
|
Re: question about updating position
[Re: silently99]
#227960
09/17/08 01:28
09/17/08 01:28
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
Serious User
|
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
You haven't explained really what you're trying to do, I'm guessing you're creating a racing game or similar and want to know only the players position If I'm right so far you can try something like function position_check(ENTITY* ent){
//me = ???;
if(vec_dist(my.x, endpoint.x)) < vec_dist(ent.x, endpoint.x)){
return(1);
}else{
return(0);
}
}
function update_position(){
while(1){
position = 1;
position += position_check(ai1);
position += position_check(ai2);
wait(1);
}
} I haven't tested any of this, it's really only for guidance You'll need to set what me is in the 1st function, and repeat position += position_check(ent_name) as necessary for any additional opponents Hope this helps
|
|
|
|