How do I Pathfind an enemy towards his Turret target?

0 favourites
  • 10 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Could you expand on this?

    first pick the family by UID using the Turret Behavior's TargetUID, and try to pick one of the object with same UID.

  • Do you have acces to families ?

  • Do you have acces to families ?

    Yup! Personal edition

  • 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.

  • 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?

    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:

    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"

  • 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.

  • 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!!

  • Not needed, i messed up in understanding the question.

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