Pushing the path finding behavior, and some questions on it.

0 favourites
From the Asset Store
Move around the rectangular and travel as much as you can!
  • This forum post was made after discontinuing an old thread I realized is far more extensive than just the few questions I started out with.

    My goals are and will have to remain for this thread:

    1.) Use the Pathfinding behavior.

    2.) Use a custom LOS ( Line of Sight ) object ( In my case an invisible sprite ).

    3.) Work for multiples of the same instance, separately and individually.

    I'll start with my last question on that forum post, I'm working on an AI behavior or path finding type ( each type is separated as modules I can request ).

    The current one I'm working on is a horde behavior, and although I know how I wanna approach it, I lack the mathmatical know-how to make it work.

    How do you make a sprite follow inbetween two moving points of the same instance?

    Say I have 2 AI_Sprites, I want a huge box around them to use as a sprite counter, I need this box to be in the middle of all of them, and follow as they move until they break off from one-another.

    I feel like the solution for this is as simple as an action, perhaps something like "distance(AI(AI.IID = 1).X/Y, AI(AI.IID = 2).X/Y)"

    I used a similar formula in my first attempt which didn't work too well.

    My current solution is casting a ray between AI#1 and AI#2, and spawning a sprite in the middle of those two points, and removing it when I don't need it.

    This works, but I know this will lag after a couple hundred of them at once.

    But obviously I'm sure someone else knows better so let me know, it has to follow the conditions above is the only take away, families are also off the table.

  • honestly, the pathfinding will get you there. but. to constantly recalculate the path will cause lag with so many instances.

    using 8 direction will help more imo. you can just simulate movement to the point you want.

    im going out. more thoughts later

  • ok so. heres the code i use to work out the mid point between 2 objects

    hoard.x+radius*((zombie.x-hoard.x)/sqrt((zombie.X-hoard.X)^2+(zombie.Y-hoard.Y)^2))

    that will give you x

    hoard.Y+radius*((zombie.Y-hoard.Y)/sqrt((zombie.X-hoard.X)^2+(zombie.Y-hoard.Y)^2))

    that will give you Y

    it basicly assumes the hoard box center is the mid point. then zombies will pathfind to a circumference in a circle around it based on where they are.

    you could give the zombies a IV for its own radius ( distance to the center on the hoard square) and adjust it randomly

    then, im thinking have them use 8D to always head to that point. as the hoard moves, they will move with it.

    hope its of use!

  • Oh no for the path finding direction I already had something in mind for it,

    All I need the box for is just to count any AI within the horde, pick any that are touching it, then select one as a lead which will then forward a path finding direction for the rest, its critical for strategy and allows hordes to break apart slowly if they don't all make it to the lead's end position.

    But if this is just to move a sprite inbetween multiples of the same instance, then this is great help, I'll plug it in with some modifications and see if it works.

    I'll tell you how it went.

  • The benefit of a horde is they all share the same calculated path of one instance.

    With the way I want to set it up, anyway; So the calculation is made once.

    1.) to pick the lead,

    2.) lead picks an end route to move on, spawns an area for other AI to call to action,

    if they don't make it, they are left behind;

    3.) And finally one more to disperse any AI within that field so that they aren't overlapping each other.

    Im confident I can do the other two, its just picking the lead that I figured Id have problems with.

    I also have a chunk system that will unrender and pause any AI not currently within proxy of the player, so lag would only be an issue if I hoarded every NPC up into one chunk and let them roam around.

    But Im sure I could fix that by limiting the number that can stay in one chunk at any given point in time.

  • i.gyazo.com/c619ad52533e9988e8ca43125b587ff3.gif

    Ok, so in this gif, it shows it working, but not for the same reasons as I hoped it would;

    You can see a box engulfing AI sprites ( which dont have any paths for testing purposes ),

    it moves to their position every 0.5 seconds, but it favors the first instance which initiated this event,

    which is why you can see it teleport back to the first AI that touched the view range of another.

    So its working, but how well it does this purely depends on the size of the container.

    It moves to the center of both AI instances its closest to within a radius of 100, I initially set this to the container's width since its height and width are even.

    But I quickly realized a circle does better at this than a square.

    But it isn't perfect, would there be any way to eliminate its preference for the first AI instance that spawned this container in so that it stops rocking back and forth?

  • yeah, on created, you need to give it a uidcheck variable. the uidcheck is for an instance of a zombie's uid. most likley the leader.

    then it always knows what instance of zombie it is specifically acting to.

    *edit* or.. is that the problem, its always choosing the same zombie, and you dont want it to choose any?

    is it you want it to set a midpoint for all zombies?

  • Okay, yeah it looks like through further testing, "radius" isnt the radius the box will move adjacent, construct takes it as distance crossed each time the event is fired.

    In other words, if the event is fired once every 0.2 seconds, and its "radius" is 2 pixels, it will cross 2 pixels every 0.2 seconds.

    The goal I'm looking for is a box that follows the average of multiple AI instances, it is then used to count how many are in said box.

    The way it works in the gif is almost backwards in how I want it to work.

    A lead AI is not picked until everyone is counted. when a horde of AI is made, I.E they bunch up, a box surrounds them to count, then pick from that count,

    - this part I can do, as shown in the gif it counted two instances inside the box.

    But getting the box to follow multiple of the same instance probably means I need to approach this in another way.

    Thankfully I had just thought of something that may work, when a AI is close to another, I could store their positions in a library, if they get to far from each other they are removed from said library.

    Ill do that, unless you have an idea on how I could fix the above.

    I realize there was some confusion on what I wanted to do, sorry about that, but this should clarify.

  • yeah, ok. i hope i see what you want.

    box to follow the hoard (who is in the library. and to stay middle of the hoard. so when some leave, they are removed from the hoard.

    cos(B-C):\cos(C-A):\cos(A-B)

    one way of getting the centre of 3 points (triangle)

    but, thats just one way.... i think its the best, as it doesnt care what type of triangle it it

    omnicalculator.com/math/centroid

    (this website has a ton of math that you could try)

    Gₓ = (x₁ + x₂ + x₃ +... + xk) / k

    Gᵧ = (y₁ + y₂ + y₃ +... + yk) / k K is the number of zombies. G is center point

    this is the simplist i could find to get a center point for more zombies.

    so, that should find a mid point constanly between all zombies within a hoard.

    wow this takes all my time. i pray this works and i understood what you needed lol

  • First one is Cos or cosine of A and B, you typed it twice, had it been Cos and Sin it would give me a clockwise and counter clockwise view.

    Second one is asking for the number of zombies, which, I don't have.

    The point of what I'm trying to do is get that number which is why although I'm sure it would work, your adding the position of all zombies then dividing it by the number of them, I just don't have the number to begin that division.

    Also, I don't think Construct allows " ... ", I know some programming languages will take that as " so on and so forth ", but I don't think Construct has that operator.

    The website you showed me might be useful for future use, it looks like a generator which is super handy and might use for future projects, thank you for that, but unfortunately it looks like Ill have to keep looking.

    I have a solution under my belt which may work but it'll be quite complicated to create.

    But I dont want to do it if I know I'm absolutely sure it's possible to do this with a single expression, I think I'm close but perhaps we need extra brains to hop in on this thread to lend assistance.

    Thank you for your time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i thought that was the whole point in the hoard box? to check the number of zombies inside!

    test it by having it static, and add zombies to it. to see if you can get it to count.

    then all you gotta do is set its location to the mid point using the math.

    thats the aim right? have a hoard box so zombies behave as a whole, then when 1 leaves the hoard they can act indipendantly.

    but whatever. was just trying to help

  • Looks like I am terrible at constructing sentences,

    No you are absolutely correct, sort of.

    Your assuming they all act in unison which I dont want them to, having so many chances to drop off means they all can act individually.

    I can change their AI behavior on the fly,

    but with the way you portrayed it, if a group of zombies spot you, the whole horde moves in unison towards you.

    This is good for zombies but Im not making zombies, lets use a different analogy, how about an army soldier.

    When they form a army, a leader is who sets the first goal to move, but at any point the player approaches an individual army soldier, they dont ALL jump on the player, its only the few that spot the player that do; Else, they continue moving along their path set by the leader

    when to many soldiers get close to each other, I want a box to spawn around them, count the number of soldiers.

    The box count is used to PICK from any zombie in the horde to act as the leader.

    When a leader is elected, the leader spawns another object, this object is a "CallToAction", it selects every soldier overlapping it ( its a large object ) and spawns yet another object which is a way point which sets the X and Y pos for their path finding to move towards.

    This part I can absolutely do, this is easy, its just the first step I can't do of making a box follow them to count everyone still in it.

    Any soldiers that don't hit the CallToAction are dropped off, they didnt make it, or they were too far away.

    Rereading my last post's order only made sense in my head, but yeah I can see how its confusing.

    The first formula you sent me was incredibly close to what I wanted, but the way it behaved upon further testing showed it wasn't quite what I was looking for, and on top of that,

    was not exactly what you said it did, here, let me post the original formula you made to see if I got anything confused:

    so for both X and y I did with adjustments for both obviously:

    AIGroup.x+300*((zombie.x-AIGroup.x)/sqrt((zombie.X-AIGroup.X)^2+(zombie.Y-AIGroup.Y)^2))

    so if I typed this correctly, the original formula said " hoard.x ", plus radius number,

    times Zombie.x subtracted by hoard.x,

    Then divide both by a square root of the power of 2, plus zombie.Y and hoard.Y to the power of 2.

    Upon further testing this seemed to have just worked like a lerp(), just longer written,

    It did have some weird effects to it that I can't quite explain where it looked like it was trying to get the position of ALL AI within that radius, but I imagine thats only because this effects all AI within that radius, so the box just teleports around trying to move over every single one.

    It did favor the first AI instance that initiated it though, so it usually hovered around it.

    Most of the solutions above either work but are impossible to add,

    Or don't work at all.

    I genuinely think its a misunderstanding thats stopping us from coming to a solid conclusion, this should be as simple as an expression, I just can't think of it.

    So instead of focusing on the whole goal I just need to know how you make a box follow multiple of the same sprites that are close to eachother.

  • i was explaining loads about midpoints to work out where the box should be.. but..

    just make a box follow a group..

    can the box stretch? does the box have to interact with anything?

    you could just have each soldier in the hoard have a line between them.

    it would be a square.. not a solid one

    if it needs to be solid, there are ways to edit a tilemap using a brush that gives it a solid shape. that i know very little about, but did notice it as a new feature to c3

    let me know if we were on the right tracks with the square being at a midpoint. for can do it with hierarchy, as you can work out how many are in the hoard as you can count children

  • Nope, it only follows and counts, I could have it change size to fit more but Id rather control that through a variable.

    Perhaps an elected lead soldier would have more influence, thus a greater horde range.

    In the old thread I did something similar to that line work with the only difference being a box follows the line at its middle image point, the square would change its width and height to equal the length of that line.

    It works but having that many instances all at once just to do something that could probably be done mathematically seems abit much.

    Itll fix my problem but make another one in its place.

    But yes, I know its anti-climatic but I literally am just asking how to make a box follow between multiple AI, only letting them go if they stray too far.

  • Alright I've settled on a simple solution with a complex one being tried out in the future.

    Thanks for the website you gave me, it's an excellent resource to have, and thanks for the assistance; Really helped me think.

    The solution I settled on was just making a box, don't move it, don't do anything but count, and elect a leader from that count then finally delete the box once a horde is established.

    The lead makes a call to action zone, anyone outside of it isn't effected and is left behind.

    The call to action zone then makes a mid point, or final destination in its center which they all move to.

    Destinations are stored in a library, which I can curate by typing it in.

    Its not costly for performance, I don't think, they all behave in unison but can easily break off and do literally anything else if interrupted.

    Anytime a AI is interrupted but then left alone after a while, it returns to walking down that route.

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