Big problem with units (pathfinding & collisions) - RTS game

0 favourites
  • 12 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hello,

    I'm new to Construct 2 and I'm trying to create an classic real time strategy game since a few weeks. Things went very well at the beginning, but now I'm completely lost (I've already searched for a solution here on the forums, found nothing):

    At the moment all the units in my game can move directly through other units (something I don't want), but when I'm setting them to solid, the units won't move at all in most cases (I guess a unit "stands in it's own way", regarding the pathfinding).

    When I change the obstacles for pathfinding from solid to custom and add the unit types manually, it only works if the unit type of the unit itself is not added (example: a light tank can be obstacle for a heavy tank, but other heavy tanks can NOT be obstacles for your heavy tank...). I think the problem is exactly the same like it is when giving the units the solid behaviour...

    I hope my explanation is somehow understandable. Is there a way in Construct 2 to create a RTS with 'solid' units moving around?

    Does anybody have any idea or hint for me?

    Your help would be greatly appreciated.

    Thanks for any reply.

    Best Regards


  • You can set Solid enabled/dissabled in an action.

    So right before you Regenerate obstacle map and Find path, dissable the Solid for the object you want a path for.

    And enable after it after the on found the path.

  • Here's one solution:

    It basically just moves separate units away from each other if they get too close.

    Another idea floating around the forum is to use the physics behavior on the units so they push each other. For best results there you'd want to move the objects using the physics behavior instead of letting the pathfinding behavior do it.

  • Thank you both very much! (Sorry, not much time the last weeks for game developement... )

    Sadly, the first Solution didn't work for me , I will try the second one... If anybody knows a possible third option to try out, please just let me know.


    Best Regards,


  • Find a path with a solid sprite is in fact easy. Just set the origin on the right and 3 pixels outside the collision polygone. With a good cell size and a relative big border, it will avoid other solids. You can add the 'push out of solids' from the 'custum movement' to avoid them getting stuck or (better) use wat R0J0hound wrote. But you can not use the origin to rotate. Dooing this with a gost could work, keeping the face sprite aligned facing to the current waypoint in the path.

    Pathmoving will avoid solids because of the cell size and cell border. NOT beacuse of the fact that the obstacles are solid. To include moving solids you will have to recalculate regions arround those objects a lot. There is an action for that. But do not expect wonders. Do not expect close encounters. Do not expect it to move trough small gates.

    Give me a base capx. And i try.

    Other (probaly better and more elegant) solutions go from using bullet to move an object from waypoint in the path to the next waypoint(i can show you that), to coding your own pathfinding (there are examples in the forum).

  • Thanks for the hint, didn't thought about starting outside the polygon. I will give this a try in my next development session (and experiment with the cell size)! (If I fail I can provide you a capx of course, but I don't want to steal your time. )

    Again, thanks for reply!

  • Example with solid pathfinders avoiding eachother. ... DQ3MXNMUFE

  • 99Instances2Go: Thank you very much for the link!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound I want to thank you first, you are the best, the tutorial helped me a lot.

    BUT i got a problem, every time more zombies come to me (more than -+20 ) it gives me a C2 error: (like this)

    Javascript error!

    Uncaught RangeError : Maximum call stack size exceed

    http;xxxxxxx/preview.js line 4722 col 52

    Ther might be a bug in C2...

    And after showing this and pressing OK it got a bigg framedrop ~15-25 fps.

    What can i do?

    Are ther 20 zombies to much?

  • Radulepy

    I don't get that error in the example I posted, even with more than 20 enemies, so I maybe you do something different in your capx.

    In most cases a javascript error is a bug so maybe try making a minimal example that causes it and post it in the bugs section.

  • This is a solution,

  • Maybe it's too late, but thank you raptor!

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