Astar + formations and UCC not working well on terrains ?

Cheo

Member
Hello, I'm having an annoying issue with the Astar integration for the formation pack : I'm trying to have a team of 5 basic UCC characters follow the Line task and reach a point across a terrain, but this apparently works much better with the NavMesh system !
More precisely, there's no difference when working with a flat terrain or one with low height differences, but it seems that from a certain height irregularity level Astar shows its limits : the squad members do form a line, but then stay immobile unless their number is reduced to 3 or 2, in which case the reduced squad can move and follow the target transform as expected ! On the other hand this issue does not happen with NavMesh agents : they will execute the line task as expected on the same terrain (nav meshes are correctly baked in both cases).
This is a strange and frustrating issue on which I've already spent a lot of time, I'd be very thankful to whoever can help me ! Can anyone manage to move around as I described a small squad of UCC characters on an uneven terrain using an Astar formation ?
 

Justin

Administrator
Staff member
This is likely a difference between the navmesh and A* in terms of how they handle destinations. If you place a debug line within IAStarAIFormationGroup.SetDestination is the destination above or below the terrain? And does A* say that it is a valid destination?
 

Cheo

Member
I'm sorry, I can't find this IAStarAIFormationGroup interface anywhere (even searched the whole solution), does it require some specific definitions ?
I also did what I should have done in the first place and made a quick test with simple cube agents : it turns out that Astar presents the same limitations, the issue is not about UCC but Astar and possibly Behavior Designer.
 

Cheo

Member
Hello, I did find the script but don't know how to check if a path is valid ? Astar provides some debug gizmos by default and I made an interesting discovery :

Capture d’écran (279).png

This comes from a simple test with 5 agents on a terrain following the line task but staying in place after forming a line. As you can see, all four agent gizmos are at the same height as the leader's ! As I said formations do work on a flat surface, so the irregular height must be the source of the problem !
One last thing I forgot to mention : the "Right" bool from the Line task is off, and yet the four agents position themselves on the leader's right ! When deleting three of them the remaining two start moving and the only follower left does position itself on the leader's left as demanded.
Hope all this info helps !
 

Cheo

Member
Alright, I was able to use Walkable and hasPath and both bools return true at all times (with the exception of hasPath returning false once at start for each agent but that seems to be normal). When using more than 2 agents each destination corresponds to an agent position (the blue shape on the image I posted).

I'm about to create a similar thread on the Astar support forum, on which I'll share a link to this page. I really hope you and Astar's devs can provide a fix, your assets are really useful and it's a shame BD and Astar are facing such a limitation - I mean their combination becomes unusable on levels that aren't entirely flat, not trying to be rude but this isn't normal, no one who bought these assets together would expect such a limitation !

Once again thanks for your time and I hope there will be a solution, if so I'll be sure to share some footage of an rpg squad prototype I'm making with UCC, BD and Astar !
 

Justin

Administrator
Staff member
A bullet proof way would be to fire a raycast from high above ground to the ground position in order to get a valid destination, but I am curious what the A* community has to say for a way to handle this.

if so I'll be sure to share some footage of an rpg squad prototype I'm making with UCC, BD and Astar !
Looking forward to it :)
 

Cheo

Member
Copying what I wrote in another thread in case someone has the same issue : using a raycast is indeed a good solution, here's what my Line script now looks like :

C#:
using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using Tooltip = BehaviorDesigner.Runtime.Tasks.TooltipAttribute;
using HelpURL = BehaviorDesigner.Runtime.Tasks.HelpURLAttribute;

namespace BehaviorDesigner.Runtime.Formations.AstarPathfindingProject.Tasks
{
    [TaskCategory("Formations/A* Pathfinding Project")]
    [TaskDescription("Arrange the group in a straight horizontal line.")]
    [TaskIcon("Assets/Behavior Designer Formations/Editor/Icons/{SkinColor}LineIcon.png")]
    [HelpURL("https://www.opsive.com/support/documentation/behavior-designer-formations-pack/")]
    public class Line : IAIAgentFormationGroup
    {
        [Tooltip("The separation between agents")]
        public SharedFloat separation = 2;
        [Tooltip("Should the formation be to the right of the leader?")]
        public SharedBool right;
        public LayerMask mask;

        protected override Vector3 TargetPosition(int index, float zLookAhead)
        {
            var leaderTransform = leader.Value == null ? transform : leader.Value.transform;

            Vector3 returnedTarget = leaderTransform.TransformPoint(separation.Value * index * (right.Value ? 1 : -1), 0, zLookAhead);

            if (leader.Value != null)
            {
                Vector3 targetCheck = returnedTarget;
                targetCheck.y += 10;
                RaycastHit hit;
                if (Physics.Raycast(targetCheck, Vector3.up * -1, out hit, 50f, mask))
                {
                    returnedTarget.y = hit.point.y;
                }
            }
            return returnedTarget;
        }

        public override void OnReset()
        {
            base.OnReset();

            separation = 2;
            right = false;
        }
        
    }
}

The post I left on the Astar forum received no answers though, maybe I should bump it. Oh and even though this script isn't complex, could you please integrate this raycast check for each Astar formation script, so that we don't have to it ourselves ? Thanks again for your help ! I'll post a first video of my prototype in a few days as promised :3
 
Top