Is there a better way to handle RTS object avoidance?

For questions about using Classic.

Post » Sun Apr 12, 2009 12:38 pm

Well, I just started using Construct, and I've been playing around making an RTS based on the RTS example that comes with the program. Right now, when you set the units to avoid eachother, they sort of smash into eachother and come to a standstill before moving again.
Obviously it isn't very realistic for people to crash into each other like this, so I'm wondering if there's a smoother way to make the units avoid each other.

Also, I want the units to kind of spread out at their destination. I tried making them move to a random point around the mouse when the player clicks, but often their destinations still overlap and they sort of try to "fight" for a specific spot. It'd be nice if I could have them move to a position around the destination based on where they were standing when they started, since that would fix my first problem as well, but I have no idea how I would pull that off.

Basically my question is, what's the best way to set up RTS movement for human units from a top down perspective?
B
4
G
3
Posts: 31
Reputation: 964

Post » Sun Apr 12, 2009 4:10 pm

[quote="Pythagoras":1czmj3iw]Right now, when you set the units to avoid eachother, they sort of smash into eachother and come to a standstill before moving again.[/quote:1czmj3iw]
I spent a while programming this. I couldn't figure out a better way. You could turn it off and try inventing your own system using invisible sprites as detectors.

[quote:1czmj3iw]Also, I want the units to kind of spread out at their destination. I tried making them move to a random point around the mouse when the player clicks, but often their destinations still overlap and they sort of try to "fight" for a specific spot.[/quote:1czmj3iw]
That's the problem with giving them random positions to move to. You should try using a predictable algorithm which wont give overlapping destinations, like creating a regular grid of targets.

[quote:1czmj3iw]It'd be nice if I could have them move to a position around the destination based on where they were standing when they started, since that would fix my first problem as well, but I have no idea how I would pull that off.[/quote:1czmj3iw]
When giving a move command, calculate the average position of all the selected units, then store each unit's offset to the average position in a private variable. Apply this offset to the clicked move spot and they'll keep their relative positions when moving. You'll probably need a few for each loops in a subevent to do that.

[quote:1czmj3iw]Basically my question is, what's the best way to set up RTS movement for human units from a top down perspective?[/quote:1czmj3iw]
Fiddle with the RTS behavior parameters until they work for you. That's it really. RTS games are hard work to make. You picked probably the hardest first project you could've :P
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sun Apr 12, 2009 4:26 pm

Thanks for the speedy reply!

I'll give all your ideas a shot. I'm fairly new with Construct, but I've had a ton of experience with making games before, and this program is so intuitive it makes everything really easy.

I know, making an RTS is a bit of a challenge, so I hope I can get it to work.
B
4
G
3
Posts: 31
Reputation: 964

Post » Sun Apr 12, 2009 7:49 pm

Quickest way I've found to fix the bumper cars thing is to set their cell size bigger.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Apr 13, 2009 9:59 pm

I'll give that a try, and get back to you.

I've also tried to the units "fighting" over the point where the player clicks. Basically, what I did was set it up so it checks if another unit is taking up the target area, and set it to place the target 32 pixels out from the old target. The only problem is, they seem to reach the destination, realise that they're overlapping that position, so they keep picking a new one over and over. Is there a way to only make it check for objects that aren't actually the original object itself?

My next problem is, I have a bunch of NPC units that I want to walk towards the nearest player controlled unit. The NPCs are using the RTS behavior, and I can get them to move towards the player's units when they get within a certain range, but they always go for the original object, and not the ones created in runtime. There doesn't seem to be a way to set it to go towards the nearest object, so I can't really figure it out.
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 4 guests