Any methods to prevent an object of the same Instance from picking itself when looking for another?

0 favourites
  • 12 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • The idea for this custom AI behavior is an Interceptor,

    If me the player is busy with dealing with AI #1,

    AI #2 will jump in when I'm in engagement distance of AI #1.

    I previously had gotten this to work, but every time I add a new AI Module/behavior, it breaks, or something breaks, Bit tired of Construct's Path finding behavior and if this keeps up I'll just have to make my own, which ive seen people suggest doing in the forums.

    I don't want to do this because I've already broken through so many hurdles people usually give up on with this path finding behavior and I would love to share what I found to finally give people answers that traditionally, forums go inactive due to not having a solid answer for.

    I'll send picture of the project file, I know I'm going to get questions as to why its messy or, why I'm using so many "unnecessary events", which will give me extra to read into so when you get a hold of this picture, try to refrain from mentioning it;

    Now because I agree that these questions are valid, know that I can always minimize my project later on.

    Also, everything in this picture is required for the AI to function,

    This is a test bed project so everything is very minimalistic.

    So although I doubt it'll be brought up, just incase, try not to divert your focus; We cannot solve this without your 100%.

    The picture will show the structure of how events should play out in order and what most of the relevant ones ( to this problem ) do.

  • This isn't relevant to the problem but it does show in action how all of this works.

    These are gifs of my AI in action.

    Interceptor ( when it sort of works )

    i.gyazo.com/fe2823c08cc625c7cd208861d2144937.gif

    Aggressor

    i.gyazo.com/f5f8930650db6a83490a6764fc3d174d.gif

    Self-Preservation

    i.gyazo.com/dc5e3e126ff960110c22a78fdd6fd162.gif

    So this is proof of concept that this does work, but I have to fix it after adding something new just about everytime.

    And yes this does still hold up when there are multiples of the same instance, I make sure of it with condtions and variables narrowing it down, this thankfully still works even at the current version of this project.

    This also works without families, and If possible I'd like to keep it that way.

  • So the issue is “Sprite: has LOS to sprite” is picking itself? The solution is to use a different object. A family with that sprite is one solution

    Which would look like this:

    For each sprite
    Pick otherSprite by comparison: otherSprite.iid <> sprite.iid
    Sprite: has los to otherSprite
    — do something

    You can also do the same with another dummy sprite. The idea is you create one per sprite instance. So there is a setup step, and an update step. Well unless you pin them together.

    Start of layout
    — dummy: destroy
    — for each sprite
    — — create dummy
    
    Every tick
    — dummy: set position to sprite
    
    For each sprite
    Pick dummy by comparison: dummy.iid <> sprite.iid
    — do something
  • Each AI instance actually has room for option 2, but I didn't think I'd ever need to utilize this as a method to get it to work.

    Each AIHolder has a Variable "Entity ID" or EID, which it would use to spawn a sprite according to that EID.

    I won't be doing the keep each AI instance as a unique one, because thats not the direction I'd like to take.

    Its the easy path out and although attractive Id have to make a unique instance for every AI Id implement, and likely copy and paste code for each.

    So long run, not optimal, also not as customizable as it would first seem.

    I'll first try the family method then try the dummy sprite method ( since there is room for it and it was technically planned, kinda ).

    Thanks for the reply, I'll be back with you if it is or isn't the solution.

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

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

  • Else after a looping event block doesn’t seem too defined to me. Also you are toggling the Boolean instead of just setting to true. I suspect that is part of your issue.

    That said those are just general thoughts. I cannot follow your events and only have a vague idea what they are supposed to be doing.

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

  • Basically by not defined I mean having an else after a loop makes no sense to me. When does the else run? When the loop ends?

    Guess you’ll probably want to break it up into chunks to test and verify it’s doing what you are thinking it’s doing and then adjust accordingly.

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

  • Try Construct 3

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

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

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

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