Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
0 registered members (), 631 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
RTS auto-attack problem #181912
02/04/08 10:15
02/04/08 10:15
Joined: Jan 2008
Posts: 4
N
NoDawn Offline OP
Guest
NoDawn  Offline OP
Guest
N

Joined: Jan 2008
Posts: 4
Hello, everyone. I’m making an RTS in gamestudio and I’m progressing nicely. However, I’ve encountered a problem.

This is the situation: I want units to automatically fire on an enemy unit when they get within firing range. I figured the easiest solution would be to c_scan every frame, and compare the distance to the nearest enemy unit to the maximum firing distance of my unit.

However, my guess is that performing a c_scan for every unit(could be over 100), for every frame, might be a bit too much. I’ve also given thought to only performing it every quarter, half, or even full second. However this might create some small disadvantages, units with a smaller range could have up to a full second more to walk to the other unit, while being in his range the entire time, without this unit knowing it. This would create inconsistency, which I want to avoid at all costs.

So, I don’t have a clue what to do. Are there other methods I could use, or should I just go with the inconsistent scan anyway? Or might even that be too cpu-intensive?

Re: RTS auto-attack problem [Re: NoDawn] #181913
02/05/08 09:18
02/05/08 09:18
Joined: Aug 2005
Posts: 390
Florida
O
oldschoolj Offline
Senior Member
oldschoolj  Offline
Senior Member
O

Joined: Aug 2005
Posts: 390
Florida
What I would do is compare vectors, i dont know if yo uhave a method all squared away now but I would do something like this:

Code:
#define AGGRO_RANGE skill1
#define ANIMATION_SPEED skill2
#define ATTACK_RANGE skill3

VECTOR temp_enemy_vec
vec_zero (temp_enemy_vec);


if (vec_dist (my.x, player.x) < player.AGGRO_RANGE)
{
if (vec_dist (my.x, player.x) > my.ATTACK_RANGE)
{
my.ANIMATION_SPEED += 6 * time_step;
vec_set (temp_enemy_vec, player.x);
vec_sub (temp_enemy_vec, my.x);
vec_to_angle (my.pan, temp_enemy_vec);
my.tilt = 0;
ent_animate(my, "run", my.ANIMATION_SPEED, ANM_CYCLE);
c_move (my, vector(my.MOVEMENT_SPEED * time_step, 0, 0), nullvector, GLIDE | IGNORE_YOU | IGNORE_PASSABLE);
}

if (vec_dist (my.x, player.x) <= my.ATTACK_RANGE)
{
vec_set (temp_enemy_vec, player.x);
vec_sub (temp_enemy_vec, my.x);
vec_to_angle (my.pan, temp_enemy_vec);
my.tilt = 0;
my.ANIMATION_SPEED = 0;
while (my.ANIMATION_SPEED < 100)
{
ent_animate(my, "attack", my.ANIMATION_SPEED, NULL);
my.ANIMATION_SPEED += 6 * time_step;
wait (1);
}
}
}



Of course this need to be inside a while loop, and it doesn't take into account any of the other factors when dealing with enemy AI, but you could probably safely use something like this for alot of enemies.


you can find me with my face in the keyboard, unshaven, listening to some nameless techno tragedy, and hashing through code over a cold cup a stale joe. __________________________________ yours truly

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