Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (degenerate_762), 1,098 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
multiple targets(enemies) #472328
04/21/18 02:18
04/21/18 02:18
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
I am puzzling around with this for quite a while now.

My AI should target the nearest suitable enemy.
The ENTITY of it's enemy is locally stored in the definition "my.enemy".


Code:
function find_enemy()
{
	for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
	{
		if ((you != my) && (you.team != my.team) && (you.health>0))// go through all models with the correct specs
		{
//somehow determine the nearest suitable enemy
			my.enemy = you;//
		}
//////////
//somehow repeat the function, so that the AI can find new targets, if one happens to die or if another is closer.
	}
}


Re: multiple targets(enemies) [Re: Blobfist] #472350
04/22/18 17:58
04/22/18 17:58
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Assuming the code you posted is working right now (except for nearest part),

what you should do is simple.
set my.enemy to null at the start of the function.

then before the my.enemy = you like check 2 things.

1- if my.enemy is already null set my.enemy to you.
2- if my.enemy is not null, you are going to check if current my.enemey is farther away from new "you". you can use if(vec_dist(me.x,my.enemy.x)>vec_dist(me.x,you.x)) .
if that is true then entity stored in my.enemy is not closer, the one in you is closer so you set my.enemy = you.


3333333333
Re: multiple targets(enemies) [Re: Quad] #472373
04/23/18 17:21
04/23/18 17:21
Joined: Mar 2018
Posts: 37
Blobfist Offline OP
Newbie
Blobfist  Offline OP
Newbie

Joined: Mar 2018
Posts: 37
Including "my.enemy = NULL;" is what I was missing.

This code works perfectly smoothly tongue

Code:
function find_enemy()
{
	my.enemy = NULL;
	//////////
	ENTITY* Entenemy;
	var next_target;
	//////////
	for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
	{
		if ((you != my) && (you.team != my.team) && (you.health>0))
		{
			if(my.enemy == NULL)
			{  
				my.enemy = you;
				Entenemy = my.enemy;
				next_target = vec_dist(my.x, you.x);
			}
			else
			{
				if(vec_dist(my.x, you.x) < next_target)
				{
					my.enemy = you;
					Entenemy= my.enemy;
					next_target = vec_dist(my.x, you.x);
				}
			}
		}
	}
}




Thank you!


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

Gamestudio download | chip programmers | 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