Tactical Task Attack not firing

I have implemented IAttackAgent and the AttackDistance() is firing. But when the NPCs reach the target it just stands there and the Attack(Vector3 targetPosition) method is never fired. What can the problem be?
 
Attack will be called after CanAttack returns true. Did you implement CanAttack and does that get called?
 
CanAttack will be called when the agent is within distance and can see the target. It depends on which task you are using but tacticalAgent.TryAttack calls CanAttack/Attack. I would place a breakpoint within the OnUpdate method of the tactical task that you are using to try to see what condition is returning false.
 
I have a similar problem but with the Shoot and Scoot task. Basically the agents travel to their target, stop and then do nothing else. From looking at the code, it appears the agents never reach their destination, therefore don't run the tacticalAgent.Tryattack call.

Further investigation reveals the problem to be with the NavMesh Agent Base Offset. Basically if you set it to 0 it then works, but any other value fails. Unfortunately this isn't really solution, as setting the base offset to 0 causes the agent to sink into the ground.

Do you know of a better solution to this problem, as I envisage this may cause problems with other tactical tasks.
 
Hi, I've have replicated the demo scene (Shootable script which instantiate bullets on Attack + Heath script) in my project but I can't figure out why Attack(Vector3 targetPosition) is not begin called. No bullets are spawned.

The sequence ChasePlayer is triggered with a boolean. My Attack task is then triggered depending on a Conditional Evaluation (WithinDistance).

1614171703694.png

I added a bool int the Shootable script to see when canAttack() is set to true and surprisingly, it turns to true when the game starts even though the agent is not in the ChasePlayer sequence + is very far from the player.

1614171855790.png

Could you guide me through the proper steps ?
Also, I could see that in the demo, there is another script called BehaviourSelector. Is this a script I have to implement also?
PS : Sorry if this post seems newbie, I'm self-taught regarding programming and it's kind of hard to cope with new pipelines :/
 
Last edited:
Ok, after some analysis of what is called and what's not, I ended up with modifying the CanAttack() condition :
C#:
public bool CanAttack()
{
    var target = (SharedGameObject)bt.GetVariable("Player"); // bt being the BehaviourTree component attached to my character
    float dist = Vector3.Distance(transform.position, target.Value.transform.position);
   
    return dist <= AttackDistance();
}

Now I would like to know why this part of the TacticalAgent.cs is not called ? I know that I can still perform my Attach behaviour inside the modified Shootable script, but it's just to learn.

1614197339590.png
 
Top