Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Polarith AI (Free/Pro) | Movement, Pathfinding, Steering

Discussion in 'Assets and Asset Store' started by Polarith, Apr 18, 2017.

  1. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    @Polarith
    Great to see you're still replying on this forum! :)

    After investigating the lab scene, I realized I forgot to give the AIM Reduction component an environment to filter for. :confused:
    upload_2023-10-6_9-37-43.png

    It works as expected now. Thank you for the hint!
     
    Polarith likes this.
  2. zaniar_p

    zaniar_p

    Joined:
    Mar 5, 2015
    Posts:
    2
    Last edited: Oct 30, 2023
    Polarith likes this.
  3. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    Coming off 3 weeks of zero progress, trying to combine different behavior tree solutions with custom steering behaviors and targeting logic, I am now trying to break my problem into smaller parts.

    If you have time, I'd love some input on the following two questions:
    1. How can I encapsulate different combinations of AIM behaviors into "states" that can be turned on or off depending on f.e. encounter phases? (think dark souls boss fight in space)
      Is it possible to have a parent object with a rigidbody that has multiple children with individual AIM Contexts and AIM percepts/behaviours specific to a "state" and enabling/disabling those contexts depending on what's needed?
    2. How can I have ships overshoot their pursue target and fly a larger curve for another head-on attack pass instead of going into circles around the target? The goal-oriented version of this question would be: How can I make an agent prioritize turning his forward vector towards the target?
      EDIT: funny enough, a colleague of mine suggested to just introduce a delay timer after coming close to a target during which the ship doesn't steer towards the target, effectively making it overshoot the target and fly straight for a bit before turning again. Until I've tested this, please disregard this second question :)
      enemy-circling-player.gif
    Any input is greatly appreciated. I keep coming back to this asset no matter how far I stray. :D
     
    Last edited: Nov 7, 2023
  4. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    @Polarith
    On question 1.
    I've since checked out the Roundabout example scene. It's definitely a way to do it and I like the use of the Animator as a state machine. There's a few pain points, though:
    1. Comparing strings (labels) is very error prone and has a huge overhead to keep track of any changes across references.
    2. Having all SteeringBehaviours on one gameobject is cumbersome when things get more and more complex (lots of scrolling, multiple instances of the same behavior set to different values etc.)
    I can live with point 1, but point 2 is definitely a bit iffy because it goes back to my question 1 above. If possible I'd like to have better encapsulation so that I can make sure that when I want to tweak "behavior for phase A", I don't accidentally touch anything that belongs to some other phase. Is there a way?
     
  5. Polarith

    Polarith

    Joined:
    Nov 22, 2016
    Posts:
    314
    Hi @paulindrome,

    I did some experiments in the past and also used the state machine with the animator (but every other would suit, too).

    1. In fact that would be possible as long as not multiple contexts want to steer the same controller at the same time. But I think it would be easier to have multiple game objects with the behaviour combinations for each phase nested onto a game object but only a single context and you (de-)activate them when needed. I would not compare the strings, but store references to the game objects. Another option that I used in the past, is to store references to the behaviour game objects and manipulate their values directly. Then, you don't need dozens of behaviours, but only different parameter setups. Bonus: you can vary the values smoothly and also with different difficulty modes.

    2. I did some overshooting for a spcae shooter with missiles that moved like snakes (swarm missiles). I did it mostly with physics. You may check a setting with AIMStabilization or using the inner radiius (in case of a radius steering behaviour, otherwise, you need a custom component for this). A custom controller that turns in case the target vector exceeds a certain angle would be an option, to, propably with in combination with a simple state machine (as the delay timer).

    I hope that points help you. Have a great day,
    Martin 'Zetti' Zettwitz from Polarith.
     
    paulindrome likes this.
  6. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    @Polarith

    Good suggestions. Thank you very much. :)
    I've since had some success having an enemy pursue a target, fire at it when possible (non-polarith stuff) and flee from it for a few seconds when it gets too close to target, simulating an "overshoot".
    I created a struct with: a label, an enum for the behaviour type and a list of AIMBehaviours to activate.
    In a list of those structs, I can define what behaviours should be active for what behaviour type.
    Because I don't see the labels of the individual behaviours in the list, this is a bit difficult to keep track of but it works for now.
    upload_2023-11-26_18-18-55.png

    Because I don't want to duplicate contexts and behavior setups, though, I keep wondering:
    Is it possible to re-use a behavior setup across different contexts?

    Let's say I have this hierarchy setup for an enemy: upload_2023-11-26_18-24-30.png
    They can Wander, PursueTarget and MoveToTargetPoint.
    All three of these behaviors are represented by an individual GameObject in the hierarchy with a specialized context and only one of those three should be active at a time. The way I understand it, if all three of those behaviors need the same environment collision avoidance, all three need to define it for themselves, right?
    This would mean if I changed one of them, I'd have to propagate those changes to the others as well, which is a huge overhead when an enemy possibly needs more and more behaviors.

    Ideally, I'd want to define one environment collision avoidance behavior setup / context and pipe that into any other behavior setup / context that should take it into account. Is there a way?

    (I hope I'm making myself clear here. The vocabulary is a bit difficult to navigate because I don't know what I should call a "set of AIMBehaviours combining into a behavior pattern". :D)
     
  7. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    Something a little different just came to mind:
    Could I theoretically "abuse" a context with one AIMSeek behavior to determine if something is in range and within a "cone of vision" in order to trigger firing when the objective value is above a certain threshold?
    I would basically be using the radius values for range, sensitivity offset for narrowing the reception cone and checking the DecidedValue[0] for the context's only objective to trigger firing when it's above, say, 0.8.
     
  8. Polarith

    Polarith

    Joined:
    Nov 22, 2016
    Posts:
    314
    Hi @paulindrome,

    To see the behaviour names, a wrapper class might be a solution or a custom editor to your struct that displays the components name/label.
    I would use only a single context and activate or deactivate the behaviours (or nested objects) that are needed during runtime. Additionally, you can also change the thresholds of AIMContext on runtime with a script.

    Theoretically, this might work, but it sounds quite complicated. I would just store a list (maybe it is sufficient to use the GameObjects in AIMEnvironment) of targets. Then I would make two checks (think of it as filters). First, check the euclidean distance to the target. Second, check the angle between your forward (or view) direction and the target.

    Best,
    Martin 'Zetti' Zettwitz from Polarith.
     
    paulindrome likes this.
  9. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    @Polarith
    To your second paragraph: Yeah. That's basically how I am doing it now. It was just an idea. :D

    To the first: How can I tell AIMBehaviours to look for their AIMContext on a different GameObject (ideally, up the hierarchy)? As far as I can see, there is no way to do this with a single AIMContext because AIMBehaviours require the Context on the same GameObject.
    upload_2023-11-27_21-14-21.png
     
  10. Polarith

    Polarith

    Joined:
    Nov 22, 2016
    Posts:
    314
    @paulindrome,

    You are absolutely right, I forgot that I changed this for some research pruposes only. I am sorry for the confusion.
    An option that might work, is to add behaviours to AIMContext manually, by adding them to the Behaviours List. I haven't tested it, but I think it's worth a try. This way, you can have seperated child objects for the logical subgroups that you like. Each object has an AIMContext as required (you can deactivate it) and the behaviours that you like for this subgroup. A 'master' context would manage all behaviours and steer the controller. A script might search for the behaviours automatically, or you add the objects to a list that is searched.
    In the second option, you would have different game objects for each state. Each with its context and needed behaviours. This would provoke redundant behaviours, that you have to manage, but it would work. You just need to make sure, that not two contexts try to steer the controller at the same time.

    I would try the first option and go with the second if it's not working.

    Feel free to report your progress,
    Martin 'Zetti' Zettwitz from Polarith.
     
    Last edited: Dec 11, 2023
  11. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    35
    @Polarith I am coming back to this again.

    The Behaviours List is readonly. Should I be adjusting the source code? :confused:

    upload_2024-1-22_22-19-48.png
     
  12. Polarith

    Polarith

    Joined:
    Nov 22, 2016
    Posts:
    314
    Hi @paulindrome,

    Sorry for the long delay, unfortunately, I got sick. I am sure you already figured it out: you don't have to change the source code. Even though it is readonly, it only means that you cannot assign a new List to the attribute, but you are able to change the existing list by adding or removing its entries.

    Best,
    Martin 'Zetti' Zettwitz from Polarith.