Making an RTS object move to a point within range.

For questions about using Classic.

Post » Fri May 08, 2009 5:56 pm

Basically, I'm making a simple RTS, nothing fancy. Right now the player can click on an enemy unit to send his units to attack, but I'd like them also to move to a point within the range of the enemy unit, rather than moving directly to it.

This image explains it fairly well.
http://i150.photobucket.com/albums/s117 ... intlol.jpg

The red is the enemy, green squares are the player's units, and the blue circles with lines are the destination I want the green squares to end up at if the player sends them to attack the enemy.

I know from using Game Maker years ago that it had handy little lengthdir_x and lengthdir_y commands for just such an occasion, so is there something similar in construct?
B
4
G
3
Posts: 31
Reputation: 964

Post » Fri May 08, 2009 7:52 pm

This can be done using a little math. I'm not so good at explaining these things, so here's a CAP file I whipped up real quick:

RTS in Range

The goodguys have a variable called 'range'. Changing this will change the distance at which they stop.

Hope that helps. :)
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

Post » Fri May 08, 2009 8:12 pm

That works perfectly! Thanks!

I'm not very good with math, so I would probably have spent hours trying to come up with something like that.

Now, supposing I wanted to make this work for NPCs too, would this make the NPC go after the closest player unit, or to the first created?
B
4
G
3
Posts: 31
Reputation: 964


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests