Hello,
I'm quite new to the Behaviour Tree asset but I'm slowly getting the hang of it.
What my Behaviour Tree does (most of the time) / should do :
My Seek task is quite basic, based on the A* original one provided in the Movement Pack :
When the bug occurs and the editor is playing, the Behaviour Tree looks like that (I guess it shouldn't look like that) :
When I pause the editor, the Behaviour Tree change its appearance and looks like that (which should be how it looks) :
While the bug occurs, the agent's target is still valid and the agent is already at melee range. The Seek task should return success and stop.
The Repeater has Count = 0, Repeat Forever = true and End On Failure = false.
The console looks like this (Combat task runs at the same time as Seek task and the Seek task alternates between SetDestination and HasArrived):
I'm pulling my hair off on this. I can't find what's wrong..
Thanks
I'm quite new to the Behaviour Tree asset but I'm slowly getting the hang of it.
What my Behaviour Tree does (most of the time) / should do :
- the agent wanders and, at the same time, checks if the player is within sight and if it is being hit (via a custom OnGettingHit event)
- if the agent is hit or player is within sight, it will seek the player to go to its melee range.
- once arrived at destination a "subtree" is executed : (it is where the problem lies)
- agent is in combat task (only returns Task.Running) and at the same times, checks that its target is still within a certain distance
- if its target gets too far away and is no more in melee range, it returns failure, inverted to success, so the Seek task can trigger and make the agent go to its target melee range again.
- repeat this subtree.
My Seek task is quite basic, based on the A* original one provided in the Movement Pack :
C#:
public class Seek : IAstarAIMovement
{
[Tooltip("The GameObject that the agent is moving towards")]
public SharedGameObject target;
[Tooltip("If target is null then use the target position")]
public SharedVector3 targetPosition;
private EnemyManager enemyManager;
public override void OnAwake()
{
base.OnAwake();
enemyManager = GetComponent<EnemyManager>();
if (enemyManager == null) Debug.LogError("Seek.cs > enemyManager is NULL !");
}
public override void OnStart()
{
base.OnStart();
SetDestination(Target());
enemyManager.enemyAnimatorManager.PlayRunAnimation();
}
// Seek the destination. Return success once the agent has reached the destination.
// Return running if the agent hasn't reached the destination yet
public override TaskStatus OnUpdate()
{
Debug.Log("SEEKING task running");
if (HasArrived())
{
Debug.Log("SEEK > HAS ARRIVED.");
enemyManager.enemyAnimatorManager.PlayIdleBattleAnimation();
return TaskStatus.Success;
}
Debug.Log("SEEK > SETTING DESTINATION.");
SetDestination(Target());
return TaskStatus.Running;
}
private Vector3 Target()
{
if (enemyManager.enemyCombatManager.target != null)
{
return enemyManager.enemyCombatManager.target.transform.position;
}
return targetPosition.Value;
}
public override void OnReset()
{
base.OnReset();
target = null;
targetPosition = Vector3.zero;
}
}
When the bug occurs and the editor is playing, the Behaviour Tree looks like that (I guess it shouldn't look like that) :
When I pause the editor, the Behaviour Tree change its appearance and looks like that (which should be how it looks) :
While the bug occurs, the agent's target is still valid and the agent is already at melee range. The Seek task should return success and stop.
The Repeater has Count = 0, Repeat Forever = true and End On Failure = false.
The console looks like this (Combat task runs at the same time as Seek task and the Seek task alternates between SetDestination and HasArrived):
I'm pulling my hair off on this. I can't find what's wrong..
Thanks