Jump to content
  • Advertisement
Sign in to follow this  
suliman

RTS - targeting, moving close to target

This topic is 1414 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

Im doing a tilebased (A* pathfind) rts (think warcraft 2) with large tiles (one unit per tile). When i issue an attack order on a specific enemy i want to get close to it and then attack.

 

When i click an enemy i find a free, walkable adjacent tile (preferably the tile closest to where the attacker is, so the unit doesnt walk all the way around the target and hit it from behind) and set the attacker to move there. When close enough for attack (melee or ranged attack) i stop moving and attack the target.

 

But the target may move at any time, so i need to recalc the "move to this tile to be able to attack" and redo pathfinding. This may get slow right? And ranged units dont need to find an adjacent tile, just any tile close enough to the target to be able to attack it.

 

Any good way of doing such things? My method seems crude to me. What if there are many units involved? (selecting 30 of your guys to attack someone).

 

Thanks

Erik

Share this post


Link to post
Share on other sites
Advertisement

What I've done is, if you select an enemy unit to attack, the player's unit marks that enemy, and simply moves towards the tile the enemy is on.  Part of the logic in the player's unit should be CanAttack(), meaning, is it close enough to attack.  So, while you're target tile is the one the enemy is standing on, your unit will stop once it's in attack range (a few tiles for ranged units, adjacent tile for melee unit).

 

If your enemy target moves, yes, you have to recalculate, but you should always use the CanAttack() to over-ride whether your unit has reached its intended tile or not to stop moving and start attacking.

Share this post


Link to post
Share on other sites

ok but the tile the target is currently standing on is not walkable (and not "pathfindable") though since its blocked by the target unit itself. Maybe make an exception for that specific tile...

 

But basically this is how its done?

Share this post


Link to post
Share on other sites

ok but the tile the target is currently standing on is not walkable (and not "pathfindable") though since its blocked by the target unit itself. Maybe make an exception for that specific tile...

 

But basically this is how its done?

I think that's flawed.  You should be able to select any walkable tile for pathfinding, whether a unit (enemy or friendly unit) is on it or not.

 

If you select a tile a friendly unit is on, the tile is the destination; if the friendly unit doesn't move, then your unit will stop when it gets as close as it can to that tile.  If the friendly unit does move, then you will walk onto the tile as if the friendly unit was never there.

 

If you select a tile an enemy unit is on, then the enemy unit is the destination, and your pathfinding may have to be updated if that unit moves.

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!