Jump to content
  • Advertisement
Sign in to follow this  
Jossos

RTS Unit "agro" range (Auto attack) Help

This topic is 1006 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having some trouble implementing an efficient system for units detecting other units.

 

I was reading this thread: http://www.gamedev.net/topic/489276-generating-line-of-sight-in-tile-based-rts/

and then was reading through Game Programming Gems 2 - 3.5

 

And wish I could tack on more questions to it.

 

So I have an easilly accessible 2D array which specifies if a tile is seen by a player or not.

 

Using this, I figured I should have each player have a list of units it can currently see. Now the part I'm figuring out is how to efficiently update the list and how to have units go through and check if enemies are within agro range.

 

So for updating the list, would I clear the list, and then loop through every visible tile and add any enemies to it every update?

I tried adding/removing whenever they changed tiles but for some reason it acted so dodgy and I had code all over the place doing this. If someone has a nicer solution for this, some psuedocode would be helpful.

 

For Agro, does each idle && aggressive unit loop through the whole list of the players see-able enemy units to check distance?

I checked if the distance just between the units x's and z's were both within the units LOS before calculating distance actual distance, as I figured this would be faster than getting the length for every unit. Is this right?

 

 

I also read a suggestion of adding a unit reference to every single tile that unit can see, but that seems like a huge waste.

 

Any help is appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Every update testing against everything is rather extreme.

In many games objects have an idle loop. It comes with animations, but can last quite a few frames. That lets you save a lot of work right up front since you are only checking it every 20 or 30 or 60 frames or whatever.

As for the range check, it is generally good to have a spatial tree. That lets you test only against items within a few grid cells rather than testing everything in the world. Then you can build a range check function that test the few grid cells near the location for the items you want. Depending on your spatial tree design this can mean only a small number (1-9) of cell checks, and generally those will all be empty and pass near-instantly.

Then only when they are in proximity you can do the more expensive visibility checks on the rare instance where something is nearby.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!