• You can set up object variables in the combatant's settings (Base Settings > Object Variable Settings). Alternatively, you can add Object Variable components to game objects.
    However, you can also use object variables on combatants without any setup, as they'd automatically have (local) object variables when trying to access them and nothing else is defined for them.

    In any case, this'd largely depend on the grid cell/coordinates being fixed for a combatant, or if they're relying on which grid you're on. If they're fixed, just set them up in the combatant's settings.
    If they're depending on the grid, you'll probably best handle this in a battle start event and have the cells somehow marked (e.g. a tag to be able to find them), get their coordinates and set them for the combatants (all or just the enemies).
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited July 2021
    So. Putting this all together. Assuming that they are relying on which grid I'm on and that I want to be able to have multiple control paths in a given battle.

    In the battle start event for a given battle, after combatant spawning nodes, search for objects in the scene with the tag for the path you're looking for (i.e. tag: PathA, or PathB) and set them as vector3 object variables for the combatant that is supposed to patrol that path.
    (Lots of questions about how to set that up in the event:
    - would I do that by adding them to found data or is there another way?
    - how do I say the order that the combatant should go between the points in the path?
    - And how do I assign them to an instance of a combatant that's been spawned in terms of nodes that I'm looking for in making the event?
    - Will it work to have multiple instances of the same combatant (e.g. enemy soldier) patrolling different paths?)

    Then those combatants have an "move" ability which their Battle AI's will call when appropriate that checks a combatant float variable to determine which stage of the path their on, then moves them towards the next point on the path, then checks if they got there yet and if they did get there increments (or resets if back at the beginning) the float variable that keeps track of where in the path they are.
    (my biggest question here is the second question above about how to determine the order that the combatant should be moving along the points in the path. I imagine this will be pretty easy to do/figure out once I've correctly set everything up in the battle start event.)
    Post edited by Whatexists on
  • You can search for the objects using the Search Objects node, though I'd have separate tags/names for the individual path points, e.g. PathA1, PathA2, PathB1, PathB2, etc. - otherwise the order might not be correct.

    Points between the path could be handled by a Store Grid Cells node, which can find a Path - and use that path to move between the cells and just ... stop somewhere :)

    Assigning them to the combatants might be a bit tricky - maybe it's better to have the coordinates stored in global variables, so all combatants can just use whatever path they want.

    Multiple combatants patroling different paths should work, though you'll have to handle what happens when they block each other on their way :)
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Assigning them to global variables instead of combatant variables does seem easier but it still requires me to designate which combatant is traveling which path and my first instinct (although I've never actually done this and am not 100% sure how to =p) is set a combatant variable for each combatant who is supposed to be patrolling once the combatants have been spawned during the combat start event, and then have the "patrol" ability check that combatant variable on it's user to determine which path they should be looking to travel along. Does that seem like the right way to do that part? is there a better way?

    yeah, blocking eachother will need to be figured out. The easiest way to deal with it is design all my maps so the patrol paths don't overlap eachother. but in the long run that will be limiting.
  • Yeah ... pretty much. Though, if you set it up as a combatant variable (in the combatant's settings), the combatant would always take the path it was assigned here. E.g. combatants of kind A would always take path A, etc.
    You could use custom combatant events to make this a bit more flexible by setting a combatant's path variable in there.

    Blocking - since the path found via the Store Grid Cells node would run around obstacles like other combatants (if movement is set up for that), it'd probably only be an issue at narrow places where they can't move around each other.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Custom combatant events? I haven't used those or encountered them before. How do they work and how do I set them up?

    So I could avoid the problem entirely if I never make the paths go through areas too narrow to move past. Good to know!
  • Custom combatant events are game events (identified by a key) that can be executed per combatant. The default for all combatants are set up in Battle System > Battle Settings > Combatant Settings > Default Events > Custom Events), each combatant can replace/add to those events (replace by using the same key).

    Events can use those custom events via the Custom Combatant Event node and will start the game event (with the combatant as starting object) per combatant that's used in the node, using the event for the matching key.

    A similar thing is also available for abilities, items and equipment via the Custom Selected Data Event node.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • So I could have the battle start event use Search Objects node to find each cell tagged with an appropriate Path tag (e.g. PathA1, PathA2, PathB1, Path B2, etc), and store their coordinates as vector3 global variables.

    Then call a Custom Combatant Event node after spawning the enemy combatants, targeting the Enemy Group to trigger whatever their Custom Combatant Event is with the right key (let's say the "SetPath" key), and that will call an event which will set a combatant variable for the host combatant to an appropriate value for whatever path that combatant is going to patrol, and another combatant variable (probably a float) for which point on that path they're moving towards. The only question is how to get the custom combatant event to identify which path is the appropriate one for the combatant: could it reference what tag the cell it's spawned in has? e.g. if it's spawned on a cell tagged PathA1 then it sets the combatant variable to the key for PathA?

    Then the Combatants will have a "Patrol" ability whose event will check the combatants combatant variables to determine which path (PathA, PathB, etc) they're supposed to be traveling, and which point on that path they're moving towards, then finds the coordinates for the appropriate point on the path via the stored vector3 global variables and uses that in a store grid cells node to find a path, then moves the combatant along that path as per a normal move event, then checks whether it has reached the coordinate for that path point and if so increments the path point float to the next point on the path (or resets it).

    Does that all sound right?
  • Which path to take can be determined in different ways - this mainly depends how you actually define which paths they should take.

    If it's via the cell they spawn in, you could make this even easier and have an Event Interaction with Trigger Enter start type handle setting which path to take. Since it's not the player starting it, enable Start By Others and possibly do some check on the starting object (combatant).
    Also, use Deactivate After Event to only use it for the initially spawned combatant.

    But yeah, generally that sounds about right.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Is there an easy way to check an object variable against a global variable?
    In the animating event for the patrol ability I find myself wanting to check of the combatant's NextNode object float variable is greater than the Path(#)Nodes global float variable that the battle start event sets up to store the number of nodes in a given path (checking the combatant's PathtobePatrolled object float variable to determine which Path(#)Nodes global float variable it's checking against.)
  • Have you tried the Check Value node?
    It allows checking float variables from different origins.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • I had not even noticed it! I normally use check game variable nodes. Thank you!
  • Alright. So I've got it set up and it's basically working, although there is one situation where it breaks down and I'm not sure why: if there are two path nodes in a straight line on the grid it'll do everything right for the first node, but when it reaches the second one the character will stop moving halfway between the previous cell and the one it's moving too. It'll sit there without doing any more of the movement ability event or ending it's turn or cycling through other AI's or anything. So far if the nodes are not laid out in a straight line this doesn't happen (and in the game why would they ever need to be?) but without knowing why it's happening I'm worried it'll come up in other contexts.

    My workup is below. It seems to be breaking down during the gridMovePatrolCommand2 event, after the successfully looping before needing to increment the nextnode variable, and after another 3 1-step loops, halfway through moving into the 4th hex (the 5th hex is the next path node). The "is grid cell empty" check goes off fine for that 4th step, and the Change Position node gets activated (as the combatant does start to move into it), but seems to never complete (I have debugs after every node and it never gets to the one after Change Position, also the combatant stops moving halfway through it.) It also doesn't encounter this problem if the path nodes are not set up in a straight line. Any idea what could be causing this?

    The Battle Start Event
    - sets local float variable PatrolPath# for the number of paths 1-10 (so that I can copy this event and just change this value for doing different battles with different numbers of patrolling enemies.)
    - Then sets global float variables Path(#)Nodes to 0-10 for each path(#) for the number of nodes in each path (again something I’ll edit for each battle specifically.)
    - Then calls Path(#)Setup global event for each path, checking PatrolPath# to see if that path is being used first.

    Path(#)Setup global event (called by Battle Start Event)
    - checks the number of nodes in it’s path (up to 10, set up in Battle Start Event via the global float variables Path(#)Nodes)
    - and then searches the scene for objects with the tags Path(#)a - Path(#)j (based on how many nodes there are)
    - Then for each object with an appropriate tag stores that object as a found object with key “Path(#)(letter)”
    - Then stores the transform position of that found object as a vector3 global variable with key “Path(#)(letter)Location”

    Path (#) Combatant Object Variable setup event (Called by enemies entering trigger colliders when placed)
    - Initializes a object variable on the activating user combatant to store what path it’s supposed to patrol by setting the PathtobePatrolled float to it’s appropriate (#) (0 indicates not patrolling a path at all)
    - Then Initializes an object variable on the activating user combatant to store what the next node of their path they are supposed to move towards is by setting the NextNode float to it’s appropriate (#) (typically this is 2, 1 is the node they start in, and 0 is used only when I’m initializing the variables but the combatant is not going to patrol)

    gridMovePatrolCommand2 event (animating event for a “Patrol” ability)
    - Checks the Object variable PathtobePatrolled of the user to see what path, if any, they should patrol.
    - Then, based on that and if there is a path # 1-10 for them to patrol, checks the Object Variable NextNode of the user for what node they are supposed to be moving towards next.
    - Based on that it sets the Global vector3 variable NextNodeLocation to be equal to the Path(#)(letter)Location vector3 for that node of that path.
    - Then rotates the user to the location determined by NextNodeLocation
    - Then sets users grid direction rotation to nearest
    - Then checks whether the user has more movement to use
    - If it does :
    - stores the grid cell right in front of the user with value cell
    - Continue
    - If it does not :
    - end
    - Then checks if the grid cell cell is empty
    - It it is not :
    - End (This will need to be fixed with a work around at some point so that patrolling enemies will move around intervening objects)
    - If it is :
    - Change the user's position to cell via moving into that location via normal speed.
    - Run grid move-to events for cell for user
    - Set user to grid cell combatant for cell
    - Subtract 1 from grid move range
    - Continue
    - Then check if cell location is the same as NextNodeLocation
    - If it is not :
    - loop back to Rotating towards location determined by NextNodeLocation
    - If it is :
    - Add 1 to the users NextNode object variable
    - Then check if users NextNode object variable is greater than Path(#)Nodes global variable for the corresponding users PathtobePatrolled object variable
    - If it is :
    - then reset NextNode object variable to 1
    - Loop back to appropriate change game variable node for setting NextNodeLocation to node a for the appropriate users path#
    - If it is not :
    - Loop back to game variable fork for checking which node is next for the appropriate path#
  • If it hangs on change position, it's most likely just not reaching the position and waiting forever. I assume you're using the Change Position node?
    If you're moving by speed, try enabling Stop At Target and Secure Move.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Alright. With both of those on they're still not reaching the node they're supposed to, but after a bit (much longer then the 0.1 seconds I put in for the secure move, probably closer to 20 seconds or so) they'll finish the event by incrementing the nextnode as if they had gotten to the node and turning to head towards the path node after that one.
Sign In or Register to comment.