Is there a better way to handle RTS object avoidance?

This forum is currently in read-only mode.
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Right now, when you set the units to avoid eachother, they sort of smash into eachother and come to a standstill before moving again.

    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.

    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.

    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?

    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

  • 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.

  • Quickest way I've found to fix the bumper cars thing is to set their cell size bigger.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)