Behavior Tree - Follow, Search And Retreat

Published October 02, 2018
Advertisement

I integrated LibGDX's Behavior Tree AI module into our roguelite, vaporwave and procedural game, which is made use the jMonkey Engine 3.1.

I then created the following behavior :

- Follow enemy

- Search the enemy's last recorded position

- Return back to initial chase position

- Stop the chase after a certain amount of time

- Attacking the enemy resets the timer

Here's the behavior tree logic. Beware that it's possible there are still bugs.

subtree name:"notIsReturningToInitialChasePosition"
    invert
        isReturningToInitialChasePosition

subtree name:"notIsMovingToFollowingEnemyLastPosition"
    invert
        isMovingToFollowingEnemyLastPosition

subtree name:"notHaveSpottedEnemies"
    invert
        haveSpottedEnemies

subtree name:"followEnemy"
    selector
        parallel
            lookOutForEnemies
            alwaysSucceed
                lookAtClosestSeenEnemy
            alwaysSucceed
                (isPlayingAnimation animation:"look_around") stopAnimation animation:"look_around"
            followClosestSeenEnemy
            parallel policy:"selector"
                alwaysFail
                    wait seconds:10
                attackClosestSeenEnemy

root
    selector
        $followEnemy
        (isFollowingEnemyAlive) (knowFollowingEnemyLastPosition) ($notHaveSpottedEnemies) sequence
            resetLookAt
            moveToFollowingEnemyLastPosition
            parallel policy:"selector"
                alwaysFail
                    playAnimation animation:"look_around"
                lookOutForEnemies
        alwaysFail
            resetLookAt
        returnToInitialChasePosition


I'm new to AI programming and still have a lot of work to do for making better behavior trees. I think it's really easy to make spaghetti behaviors. Do you have any tutorials on how to create a "good" behavior tree?

3 likes 1 comments

Comments

Rutin

Very cool. :) I enjoy AI programming the most.

July 01, 2018 06:54 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement