How do I Pathfind an enemy towards his Turret target?

Get help using Construct 2

Post » Sat May 07, 2016 8:48 pm

Hey there!
I looked up help in Google and this very forum, and didn't quite find what I was looking for.

Basically what I'm trying to do is similar to many MOBAs' minion behavior - I need spawned enemies to target the closest turret/core, pathfind their way there, and start attacking once in range. Once the target is destroyed - move on to the next closest turret/core, repeat until death.

The attacking once in range is pretty easy, obviously, but I need help transferring the target picked by the built-in Turret behavior to the built-in Pathfinding behavior - probably using the Turret behavior's TargetUID - but how can I tell the cooridinates of the targeted object, especially when I don't know it's type - turret, of which there are at least 2 types, and the core?

Please help,
xoxo,
J.
B
7
Posts: 11
Reputation: 283

Post » Sun May 08, 2016 12:10 am

Hello,

If you don't know the type of the target, you can create a family that includes all the targetable objects. And then you first pick the family by UID using the Turret Behavior's TargetUID, and try to pick one of the object with same UID.
B
14
S
4
Posts: 112
Reputation: 1,287

Post » Fri May 13, 2016 4:57 pm

Could you expand on this?

Nabu0001 wrote:first pick the family by UID using the Turret Behavior's TargetUID, and try to pick one of the object with same UID.
B
7
Posts: 11
Reputation: 283

Post » Fri May 13, 2016 5:13 pm

Do you have acces to families ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri May 13, 2016 5:56 pm

99Instances2Go wrote:Do you have acces to families ?


Yup! Personal edition :)
B
7
Posts: 11
Reputation: 283

Post » Fri May 13, 2016 7:12 pm

Okay, your question is: How do i make a turrent's target to find a path towards that turret, using the turret's target UID.

Well, Bring all the objects that can be a target in 1 family.
Set the turret to target that familie.

Al you need now is an event with the condition: TurrentObj, on target acquired.
Combined with a second conditon: family, pick by UID, UID = TurrentObj.Turret.TargetUID

Now TurrentObj is picked and the family member with that UID is picked.

So the action in that event .... family find path to x = TurrentObj.X, y = TurrentObj.Y will be adressed to the right TurrentObj and the right family member.

I suppose you know how paths work, else plz read the manual.

BUT. Knowing that is your question, i also know that is NOT what you want to do. A turret has only ONE target. If you spawn 100 nasty enemys arround the turrent, then only ONE will be a target. Until you realease it as target, until you move it out of range or until it is destoyed by a kill.

Only that one enemy will find a path and run to the turret, because well, that is what you ask, and what i provided.

What you ask as a result is that they all (all 100) run to the nearest (even when they are not a target) turrent and start shooting when the turret is in there range (has nothing to do with the range of the turret). And when that turret is destroyd, they have to run to the next nearest turret and start there blast on that one.

So what you want is: all the events that you have allready in place to spawn nasty enemys.

Then an event with the condition family/object 'on creation', can be the family. Combined with TurrentObj, pick nearest, X = family.X, Y=famely.Y.

This picked the right enemy (the newly created one) and the right turrent (the nearest). The family, find path to X = TurrentObj.X and Y = TurrentObj.Y will send the right enemy to the right turret.

Now for the next turret. The only que you have is the destroyed turret.

So you need an event 'on TurrentObj' destroyd. Now the wrong turrent is picked. You want the next one. Call a function with as param(0) = TurrentObj.X and param(1) = TurrentObj.Y.

A function will start picking from scratch. In the 'on function event'. You make a subevent: system pick by comparisation. Object = family. Expression = distance(param(0),param(1),family.x,family.y). Value = 60 (whatever is good for you). This combined with a TurrentObj, pick nearest x= param(0) y = param(1)

Now all family members within a distance of 60 pixels of the destroyed turrent are picked and the nearest turrent is picked. Just make the path to find em.

I am sure you can solve the range issue yourself.

I hope you understand why there was no reaction before. The question could not be answerd in a way that also the wanted result was included.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri May 13, 2016 8:37 pm

Absolutely thank you for all of your help - thank you for figuring out what I meant, that was exactly it :)

I'm sorry to trouble you again, but could you help me with this part?
99Instances2Go wrote:Now for the next turret. The only que you have is the destroyed turret.

So you need an event 'on TurrentObj' destroyd. Now the wrong turrent is picked. You want the next one. Call a function with as param(0) = TurrentObj.X and param(1) = TurrentObj.Y.

A function will start picking from scratch. In the 'on function event'. You make a subevent: system pick by comparisation. Object = family. Expression = distance(param(0),param(1),family.x,family.y). Value = 60 (whatever is good for you). This combined with a TurrentObj, pick nearest x= param(0) y = param(1)


I want the enemies to go towards whatever tower is nearest - regardless of if it's within "range" - right now, when the last turret "within range" is destroyed, they go to where it died, and just stay there - how do I make them go towards whatever tower is nearest?

For posterity's sake, here's a relevant image: Image

I feel so silly - I'm usually a very competent programmer :)

Edit: The bottom event (Is Pathfinding moving along path) is my attempt at the range thing. It stops ALL the enemies on-screen once one has a target... I'm working on it, but I'd appreciate a little help... Apparently I should have moved this to "Beginner Questions" :)
B
7
Posts: 11
Reputation: 283

Post » Fri May 13, 2016 10:59 pm

Okay, now that i really see and know what you wanted to do.
(i did't get that the enemys are turrents)

Here is a capX;

https://drive.google.com/open?id=0B1SSu ... GJuV3BxNU0

I, ofcours, did't workout the whole gamelogic. Left mouse destroys a building. Right mouse adds a building and a enemy. That should simulate the gamelogic enough.

'sprite' can be a family, needed in your case.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri May 13, 2016 11:17 pm

99Instances2Go wrote:Okay, now that i really see and know what you wanted to do.
(i did't get that the enemys are turrents)

Here is a capX;

https://drive.google.com/open?id=0B1SSu ... GJuV3BxNU0

I, ofcours, did't workout the whole gamelogic. Left mouse destroys a building. Right mouse adds a building and a enemy. That should simulate the gamelogic enough.

'sprite' can be a family, needed in your case.


Thank you, thank you, THANK YOU!! This is -absolutely- what I wanted - thank you very much!!
B
7
Posts: 11
Reputation: 283

Post » Sat May 14, 2016 12:22 am

Not needed, i messed up in understanding the question.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 29 guests