[BUG?] UCC v3 AStar integration

JMab

New member
I've been trying to get a Move Towards ability working with AStar pathfinding in UCC v3.04. It calculates the path fine, but the avatar doesn't move at all.

I had a look at the demo AStar integration scene and changed it to mirror my project - I moved the A Star AI Agent Movement ability above the Move Towards ability, as I believe this is how they must be ordered. And I unchecked Teleport on Early Stop on the Move Towards ability.

I then changed the code in the SetDestination test script:

//m_AstarAI = m_Character.GetComponent<IAstarAI>();
//m_AstarAI.destination = new Vector3(5, 0, 5);
UltimateCharacterLocomotion characterLocomotion = m_Character.GetComponent<UltimateCharacterLocomotion>();
MoveTowards moveTowards = characterLocomotion.GetAbility<MoveTowards>();
RichAI richAI = m_Character.GetComponent<RichAI>();
richAI.isStopped = true;
moveTowards.MoveTowardsLocation(new Vector3(5, 0, 5));

The demo character now doesn't move at all, like my project. I believe it's a problem with the A Star AI Agent Movement ability, in they way it works with Move Towards, but I've been stumped on what the problem actually is for a while.
 
I think I can see some of the problem, and it is to do with the RichAI.isStopped flag. If it is set to true, the RichAI agent doesn't move, however if it is not true, the AStarAIAgentMovement will not start because of this code:

if (m_IAstarAIAgent.isStopped) {
m_IAstarAIAgent.destination = target;
StartAbility();
return true;
}

Commenting out the if statement above, but leaving the code within the braces makes the agent move.

Then, similarly to the Unity Navmesh agent, the AStar agent needs to be disabled after the destination is reached, which needs to be done in a new AStarAIAgentMovement.AbilityStopped method:

protected override void AbilityStopped(bool force)
{
base.AbilityStopped(force);

if (!m_PrevEnabled)
{
Enabled = false;
}
}
 
Also, to stop the AI agent from continuing to search for paths after the ability is stopped, you can add this to AbilityStopped:

m_IAstarAIAgent.canSearch = false;

and this to SetDestination:

m_IAstarAIAgent.canSearch = true;
 
It does look like setting isStopped would be the cause. I will add this to my list of things to take a look at.
 
Top