RTS & Yield?

Get help using Construct 2

Post » Sun Jul 14, 2013 12:33 pm

Hi,

I am searching for a solution for a Realtimestrategy Game, so that enemies moving along a path avoid each other in realtime.

Rather I am missing this feature in the actual RTS Template.

Is there any (clean) solution available?

Many thanks
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Sun Jul 14, 2013 4:00 pm

There is a pathfinding behavior that supports this functionality.
B
55
S
12
G
9
Posts: 339
Reputation: 9,574

Post » Sun Jul 14, 2013 6:20 pm

i guess you mean so they don't overlap, pathfinding alone wont cut it,
maybe an idea for an avoidence behavior or extension on pathfinding

here some interesting links
javascript-rts-demo

youtube rts

ps: hh great this guy recreated c&c in javascript,play onlinevtrix2013-07-14 18:27:41
ImageImage
B
71
S
22
G
7
Posts: 827
Reputation: 10,177

Post » Wed Jul 17, 2013 3:37 pm

Thanks for your suggestions.

@cow_trix: which one do you mean? the internal supports "regenerate obstacle map", but this feature does not work as expected in my project, even if i am using a "soft collision radius".

@vtrix: my idea is simple: every tank got all other tanks as obstacles. when collision is recognized, one of the "colliders" regenerates its obstacle map. anyway I made it, but it wont work. So i am searching for a kind of script example.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Wed Jul 17, 2013 3:47 pm

@xeed

As said before, the pathfinding can't do "all" the work here. It can help a lot though.
When you regenerate obstacle map, it doesn't work because you have some moving obstacles (other tanks) and the obstacle map cannot use those.
Instead, remove the other tanks from the obstacle map completly.
In fact, the pathfinding is correct, it founds a good path. It's the "move along path" that doesn't do it correctly for you. Instead, you should code your own movement, making the overlapping tanks stop moving maybe (so they wait for the road to be open again). If you go down this road (haha), take a look at the "Pathfinding.capx" example in C2, as Ashley displays all the nodes on the road found by the pathfinding. It will be useful to build your movement.
B
17
S
8
G
4
Posts: 473
Reputation: 6,211

Post » Sun Mar 08, 2015 5:42 am

A condition as "Select all instances, but (self.IID)" would help a lot.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Sun Mar 08, 2015 2:20 pm

it's simple.

each.. let's say 0.1 or 0.2 sec regenerate obstacle map
and subevent - foreach - instance - find path to... whereever it was moving to (through their instance variables set them to x,y) and then move along path.
i've tried for 10 boats in my game - works sofar good, BUT! when you get to let's say 100 instances or more, it might get laggy + work badly if CPU is weak, because it uses a lot of CPU power and there's a lot of sprites with movement - lots of calculations.
so to ease it up - you could set them to solids, add custom movement and on overlapping add - "push out nearest" - then reduce pathfinding to let's say... each 1-2-3 sec or simply remove the foreach and let it calculate just once(if your objects are static!) if your objects are moving you will have to use that loop
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Mon Mar 16, 2015 8:59 am

Thank you.

How did you set only other instances as obstacles? If I add all, they see themself as obstacles too... so they can't find any path, being blocked by their own instance.

Another way would be to remove an obstacle from the obstacle map. But I can't see a way to do that. I might create another thread for this problem.

Would be nice if you could share a capx.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Mon Mar 16, 2015 11:13 am

xeed wrote:A condition as "Select all instances, but (self.IID)" would help a lot.


var myIID

pick all object
pick object by evaluate where object.IID <> myIID
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Mon Mar 16, 2015 2:54 pm

Thank you very much.

I tried this before, but did not pick all object instances before the evaluation.

Is it really needed to pick all before, and why?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests