RTS pathfinding sprites not overlapping still not possible?

0 favourites
  • 8 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hey, I remember months ago I was trying to make an RTS game and I got stuck with RTS movement mechanics such as the sprite collisions. As I remember, I searched through ANY post made on this topic and could not find a proper answer on path finding sprites overlapping eachother and how to stop them, so this is kind of my last resort... IS THERE ANY WAY to replicate pathfinding sprite movements NOT to overlap but to sort of bounce off eachother and or stay in rows smartly, kind of like this video ill attach here: streamable.com/et3esr

    (and please dont reccomend adding or subtracting random coordinates for each sprite, its just not a really good workaround... I want it to be sort of similar to the video above)

    If anyone has ever succeeded in making such a movement system for sprites on Construct, advice would be appriciated, thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In that video no pathfinding is needed. If you give sprites the physics behavior they will not overlap. Just set gravity to 0 and apply forces to the objects to move them around.

    The pathfinding behavior does two things. It finds a path and moves along it. Anything we do to prevent objects from overlapping will be in conflict with it moving along the path.

    Probably a solution is to take the path and do the movement yourself instead of letting the behavior do it. Aka use the pathfinding behavior to find the path and the physics behavior to move it. Roughly you’d apply a force toward the first node of the path and once the player was close enough to that node you have to change to target the next one.

  • It's possible. I made this on Construct 3:

  • Imagine a grid that covers the entire map. Each cell in this grid can only hold one unit at a time. When a unit moves from one cell to another, it marks the cell it's going to as "occupied" so that other units can't take it. When a unit leaves a cell, it marks it as "free".

    There are two types of obstacles: temporary (like another unit occupying a cell) and permanent (like a river that the unit will have to go around).

    Every time a unit moves to an adjacent cell, it checks if it's occupied by another unit. If the cell is occupied, the unit tries to find a way to go around it.

  • Also note that many commercial RTS games with pathfinding do actually allow overlapping. Broadly speaking, they either use a system of de-collision at given intervals or at the final destination, or they use a steering/flocking algorithm that applies forces to avoid collision.

    Of course preventing overlapping completely is a thing that exists and possible as well, but it often causes issues with pathfinding when traffic happens. There are examples of developers getting this to "work", and then abandoning it later after realizing it causes more problems than otherwise.

  • I couldn't see the video because it doesn't work for me. I'm just brainstorming, and maybe this isn't the best way to do it, but maybe it'll spark other ideas. How about use a sprite with multiple image points to indicate where the units are suppose to stand and move the image sprite?

    Maybe you want to march your units in a wedge formation? Create a sprite in the shape of the wedge formation, place your image points within it, have your units fill those open positions. I was in the military. In real life, we would "fall in" to the formation we wanted before we moved as a unit. If you have the units march in a formation, they wouldn't overlap and it would be more realistic. If you have more units than spots in the formation, create another formation sprite for those left over. Just an idea.

  • Something like this?

    https://howtoconstructdemos.com/prevent-multiple-enemies-with-pathfinding-from-overlapping-easystarjs/

    Yes, something like that, but less jagged/glitchy looking, the sprites there are kind of going all over the place and sometimes overlapping and teleporting too much

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