Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 730 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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