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

Get help using Construct 2

Post » Sun Apr 17, 2016 6:18 pm

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 :cry: (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? :cry:

Your help would be greatly appreciated.

Thanks for any reply.

Best Regards
Dante
B
3
Posts: 4
Reputation: 181

Post » Mon Apr 18, 2016 8:30 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Apr 18, 2016 9:11 pm

Here's one solution:
how-do-i-chipmunks-span-class-posthilit-rts-span_p978390?#p978390
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.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Sun May 01, 2016 3:47 pm

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.

Thanks!

Best Regards,
Dante
B
3
Posts: 4
Reputation: 181

Post » Sun May 01, 2016 10:44 pm

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).
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri May 13, 2016 7:05 pm

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! :)
B
3
Posts: 4
Reputation: 181

Post » Sat May 28, 2016 9:01 pm

Example with solid pathfinders avoiding eachother.

https://drive.google.com/open?id=0B1SSu ... DQ3MXNMUFE
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 22, 2016 2:45 pm

@ 99Instances2Go: Thank you very much for the link! :)
B
3
Posts: 4
Reputation: 181

Post » Tue Aug 09, 2016 6:46 pm

@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?
B
11
S
3
Posts: 277
Reputation: 1,395

Post » Sun Aug 14, 2016 7:26 pm

@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.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Next

Return to How do I....?

Who is online

Users browsing this forum: ST314 and 35 guests