CJD's Forum Posts

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

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

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

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

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

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

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

  • Alright, Ill be closing this forum post and starting a new one, I formulated my own answers to most of the questions that I've asked but the help I got was helpful in deciding on what I should do,

    and gave me quite abit of bounce-back to enhance my thought process.

    My next forum post will be on the topic of pushing the path finding behavior, and likely will start with the last question I had on this forum post.

  • I find navigating the forum's page genuinely confusing,

    This is gonna be embarrassing but trying to find the " post new forum page " button just doesnt click in my head.

    So Ill post a question here since its critical for the next step of my AI.

    I am now working on a horde behavior, where AI move in unison.

    I need to spawn a sprite in between two of the same instance, and have it move with them, isolating it for those sprites is no longer an issue, I solved it and kinda mastered it.

    How do you spawn a sprite and have it move inbetween multiple of the same instance?

    Let me share a picture explaining what I wanna do:

    Until then Ill try to get this working myself, but any help is appreciated.

    If anyone new is reading this, I am using the same instance for my AI; I'm not changing this as its important for scaling of my game.

    I've already broken multiple barriers with my progress and don't plan on switching any time soon.

  • When the loop ends yeah, Would me switching from a for every ( loop )

    to a pick one with that characteristic not close that loop?

    In my head it would be, and correct me if I'm wrong;

    For every ViewRange...

    Pick an AIHolder who does not equal the owner of that ViewRange.

    So in otherwords, if another AI sees another AI, pick an AI in its view range that isn't itself.

    Again, this is an Interceptor AI, so it needs to know where its buddy is, and where the player is.

    If its buddy is engaging another target, jump in and attack the player.

    Maybe it would be better if I switched that for every to a pick single ViewRange because it would apply to every AI holder thats true to anyway,

    But this is the only way that worked for me so far so no chance that idea would actually work.

  • I cannot set it to true else it'll always be true for all that applies within those conditions.

    So if true means it'll follow the player, it will follow the player.

    If it isn't true it will not follow the player.

    Even if the opposite is true for either of these at some other point in time, it will still favor the first result.

    Which is why I'm forced to use a toggle since it seems to get around this issue.

    Also, I assume C2-3 read from the top down with sub events happening every other tick, don't see why a else after a loop is a bad thing.

    When I loop through all the view range instances, I close that loop by then picking one out of all of them with those characteristics.

    The reason why I don't skip the first step is because I want this to individually apply for every AI instance.

    But you did mention something interesting, what do you mean by it isn't defined and how would I better define it?

  • No ideas on eliminating random Boolean triggers?

    Because currently what I'm doing to get around this is kinda messy, I mean, anyone reading this post can see what I mean,

    All of this is to make sure the boolean is set to false when it needs to be false, and toggled if it meets certain conditions to true.

    I can't eliminate all of these and simply have an elseif statement immediately trigger something false or true,

    It just doesn't work, and I have no clue why.

    So instead, its abunch of comparisons with set false,

    And only one toggle to set to true.

  • It did not work, and I'm gonna chop that up to I don't know how even after doing research into it.

    However, good news, I came up with my own solution, it isn't perfect but it does exactly what I want it to, doesn't change my code, and works for each instance of the same object.

    Doesn't use families, Doesn't use unique objects, Doesn't use LOS.

    Well, technically it does use a unique object, but this unique object is pared with my AI anyway lol.

    Its VisionRange, which is a sprite that acts as my own custom LOS.

    Then I used a boolean, which I had to fidget with to get working, again, it isn't perfect and it tends to flip true/false on random occasions,

    But I managed to eliminate as much of it as possible.

    This whole thing is so jank but I don't mind it at all, specially considering I couldn't find these answers on any forum post, always suggesting the easy route which ever it may be,

    And trust me I've seen all kinds of methods to differentiate instances of the same object.

    Id love to post how I made this later in the forums, I don't mind sharing this tech since once it goes into a final product, it wont be recognizable.

    Here's a picture of what I did, feel free to suggest any more methods of eliminating that random boolean swapping nonsense it tends to do: