RTS AI

For questions about using Classic.

Post » Sat Mar 01, 2008 10:15 am

I'm having trouble, I'm having two bases spawn a lot of dots and send them at the other base. If they hit another dot, they die, and it works great.

Now, I want to get the dots to chase enemy dots if the enemy dot gets within a certain range. I'm using the RTS movement...and I can't figure out how to do this.

Say I tell a red dot to locate it's distance to blue dot. Well each color is an army of dots, but there are only two sprites. Getting the distance to "blue dot", is not sufficient, as there are about 40 blue dots. I need the distance to the NEAREST blue dot, then I need that dot's ID so I can chase it.

It'd be a little easier (I think), if the LOD movement had a range. I tried using turrets but that seems like a waste of resources. I'm sure there's a simple, event based way to do it. Any ideas?
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Sat Mar 01, 2008 11:24 am

This should probably go in Help/Tech

Anyway, you could try something like this:

[code:15jglt7f]
+For Each dot
+enemyDot is within # pixels
-Set dot.closestEnemy to 999999999
-Set dot.chaseMode to "On"
+For Each enemyDot
+Distance to dot is Less than dot.closestEnemy
-Set dot.targetX to enemyDot.X
-Set dot.targetY to enemyDot.Y

+dot.chaseMode = "On"
-Move dot towards (dot.targetX, dot.targetY) (or however you do it with rts movement, I don't know, I'm not on my Construct computer right now)
[/code:15jglt7f]

This will insure that the enemy dot with the shortest distance will keep their target coordinates in the first dot's targetX and targetY variables. Then you just move the dot towards that.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Mar 01, 2008 5:16 pm

I would give the turret movement another shot - it does the range checking for you, and it does it very fast and efficiently (it's compiled, optimized C++ code inside the plugin rather than events). So on the contrary, it would be a waste of resources to get it working with events when the turret movement can do what you want!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat Mar 01, 2008 6:45 pm

That would be ideal but the turret object needs a base object, and for the amount of objects I need...having two rather than one is pretty inefficient.

They need pathfinding, and I've tried assigning both RTS movement and Turret movement to a sprite. When I do, Turret movement disappears after I add it.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Sat Mar 01, 2008 7:55 pm

The turret object doesnt require a base object - it just enables the turret to rotate realistically with the base, if there is one. It's optional.

I can add both an RTS and Turret movement to an object... is there some kind of bug with that?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat Mar 01, 2008 11:01 pm

Yeah, theoretically it'd work, but I add RTS, then I add turret, then I go to the event sheet and make all the events. Then I go back to the layout and turret has disappeared from that unit's movements. It just vanishes.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Sun Mar 02, 2008 5:54 am

Ok this is really weird...now I have a bug where my RTS movement is simply not working. Their max speed is 250, they have received TargetX and TargetY, (I made sure by debugging and watching them.) They are not moving at all though. Speed is 0. That is the only movement they have, and they are not receiving any orders, only one when the application starts.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Sun Mar 02, 2008 7:35 am

Can you send the .cap doing that to ashley@scirra.com?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sun Mar 02, 2008 8:07 am

I got it working for the time being...it's working pretty good now actually. Once I figured out that the function that detects it automatically references the unique ID of whatever it found to the actions I tell it to do. (I was thinking too hard.) The turret movement finally "stuck" and stopped disappearing, and I added the targets and initial move sequence to the "On Layout Start" instead of "On Application Start". It's flawless now.

Now all I have to do is figure out a way to get the AI controller to choose multiple paths through the level to get to the objective instead of the same straight line every time, using waypoints. However, that'll be on my own time and is unrelated to this problem.

Sorry to bother ya. :D
B
5
S
2
G
5
Posts: 221
Reputation: 2,272


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests