Tank (chassis and turret) Behavior

Dramamine

New member
I'm working on a top-down tank game. I have a basic behavior tree (screenshot attached) working on the root enemy tank gameobject which searches for the player and when it can see it, rotates the entire gameobject and shoots (via Invoke Method). What I would like is for the chassis to steer the tank around while the turret looks around and if it sees the player can direct the chassis to steer and also rotate itself towards the player and shoot.

Are there any examples of this kind behavior? I've thought about a few ways to go about it:
  1. Two behavior trees that can communicate with each other (mainly the turret being able to set a destination)
  2. One behavior tree that uses Invoke Method to move the turret
  3. Custom task(s)
I'm also curious about dodging slow moving projectiles. Maybe this should be a different thread, however, my current AI does pretty well but the bullets bounce off of walls and obstacles, which often ends up with it killing itself. Any tips here?

I appreciate any help!
 

Attachments

  • behavior tree.JPG
    behavior tree.JPG
    82.6 KB · Views: 4
Last edited:
We don't have any examples with similar functionality but for this case I would restructure your tree a bit. While I am sure you could completely use behavior trees for this, in the long run you'll have more flexibility if you split your tank into two portions:

1. The tank controller.
2. The AI logic.

The tank controller is a new script that controls the locomotion of the tank, while the AI logic is responsible for telling where the tank to move or what target to shoot at. This will give a clear separation between AI versus the controller.

I'm also curious about dodging slow moving projectiles. Maybe this should be a different thread, however, my current AI does pretty well but the bullets bounce once off of walls and obstacles, which often ends up with it killing itself. Any tips here?
There are a couple of different ways you could handle that:

1. Change the projectiles so it can't kill the object that shot it.
2. Add a branch to your behavior tree which looks for projectiles and tries to avoid them.
 
Thanks for the reply, Justin.

I tried to use my existing controller to rotate the turret before shooting and had mixed results. I then came up a what I think is a good enough solution (screenshot attached) for now by creating a couple custom tasks for rotating the turret based on the Rotate Towards task. One which rotates towards the player and one which resets the turret to look forward (relative to the tank chassis) when it goes back to searching.

In regards to dodging projectiles, I tried simply using the Evade task with the target set to my bullet prefab and it seemed like it tried to avoid once. When I put that into a parallel task it seemed to be getting into an infinite loop. Any suggestions on a basic way to make him try to dodge would be much appreciated. He's likely to kill himself sometimes, but I would love to get him to sometimes be able to dodge (not just his own) projectiles.

Thanks again! I'm enjoying Behavior Trees and really appreciating the power of them especially after creating custom tasks.
 

Attachments

  • behavior tree2.JPG
    behavior tree2.JPG
    86.5 KB · Views: 9
Last edited:
Glad you got it working. You'll find that behavior trees are similar to programming in that there are multiple ways to solve the problem, and you use the one that makes the most sense to you.

In regards to dodging projectiles, I tried simply using the Evade task with the target set to my bullet prefab and it seemed like it tried to avoid once. When I put that into a parallel task it seemed to be getting into an infinite loop. Any suggestions on a basic way to make him try to dodge would be much appreciated. He's likely to kill himself sometimes, but I would love to get him to sometimes be able to dodge (not just his own) projectiles.
Projectiles are likely moving too fast for the evade task to correctly identify and move away from. When a projectile spawns you could send an event to all of the behavior trees and then start a new branch which tries to run away from the closest projectile.

Thanks again! I'm enjoying Behavior Trees and really appreciating the power of them especially after creating custom tasks.
That's great to hear!
 
Top