Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,758 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
question about updating position #227812
09/16/08 08:45
09/16/08 08:45
Joined: Aug 2008
Posts: 11
S
silently99 Offline OP
Newbie
silently99  Offline OP
Newbie
S

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] #227821
09/16/08 09:58
09/16/08 09:58
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
since ur update_postition() is called from the while(1) loop, it will keep incrementing the position when the distance is lesser than ai1_distance.

if u want the distance to be alwys updated and the position to be updated only once. then put a condition there

while(1)
{
distance = vec_dist(endpoint.x, my.x);
if(some condition)
{
ai1_distance = vec_dist(endpoint.x, ai1.x);
ai2_distance = vec_dist(endpoint.x, ai2.x);
update_position();
}
wait(1);
}


That (some condition) u can set. when do u want to update the postion only once.


A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: question about updating position [Re: delinkx] #227877
09/16/08 15:54
09/16/08 15:54
Joined: Aug 2008
Posts: 11
S
silently99 Offline OP
Newbie
silently99  Offline OP
Newbie
S

Joined: Aug 2008
Posts: 11
hmm.. so if my condition is something like

while(1){
if (distance != ai1_distance){
update_position();
}
}

it cant work becase it will still continue increment or decrement the position.

other than the distance for the condition what else can i use? i tried to make the condition like when the ai passes certain points to activate it, but it doesn't update accurately.

Any guidance on this? thanks

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
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

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

Code:
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

Re: question about updating position [Re: MrGuest] #228028
09/17/08 10:35
09/17/08 10:35
Joined: Aug 2008
Posts: 11
S
silently99 Offline OP
Newbie
silently99  Offline OP
Newbie
S

Joined: Aug 2008
Posts: 11
Hi MrGuest, yep you are right. Im trying to create a racing game.
Currently it is calculating the number of checkpoints the ai/player had passed and after that it will trigger it as a full lap.

Upon contacting with the checkpoint it will trigger the distance to the next checkpoint and updating of position (had a while loop in it). Im not sure whether is it the right way of doing it though.

Thanks for the help, i'll try it out and let you know the results =D

Re: question about updating position [Re: silently99] #228872
09/23/08 06:12
09/23/08 06:12
Joined: Aug 2008
Posts: 11
S
silently99 Offline OP
Newbie
silently99  Offline OP
Newbie
S

Joined: Aug 2008
Posts: 11
Thanks for all the help, i tweaked the codes slightly and it worked fine now.
This is the current code:

function update_distance_position(ai_dist){
if (ai_dist < distance){
return(1);
}
else{
return(0);
}

}

function update_position(){

if (you.check_identify == player.check_identify){
position=1;
position += update_distance_position(ai1_distance);
position += update_distance_position(ai2_distance);
position += update_distance_position(ai3_distance);
}
}

This function is inside the while loop.
Thanks again =)


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1