Experimenting with RAIN

First blog post, yay!

Continuing on, I started experimenting with the AI Behaviour Tree, RAIN. This came about as a task for gathering requirements for a basic enemy AI. I came to the conclusion that either a Finite State Machine (FSM, not to be confused with spaghetti monsters), or a behaviour tree.

figure2-bt-fsm
Basic difference between the two behaviours

In researching, the general consensus seemed to prefer behaviour trees over FSM, due to the dynamic and iterate-able nature of behaviour trees. In a FSM, if you want to change the decision logic when new states are added, you need to add an entirely new state, and change the relation between the different states. This can easily become a mess of spaghetti (hah) lines all over the screen.

23368-statemachinespaghetti
Pure nightmare

 

And so, I chose to examine behaviour trees; RAIN specifically, due to two things:

  1. It’s a addon for Unity
  2. It’s free

And so I set about learning how to use the basics of this system. Unfortunately, RAIN is not very intuitive at all, and suffers as a result.

After two hours of trying to decipher example code and wiki documentation, I finally managed to scrounge together a basic patrol movement.

WIP.png
Behaviour tree in the bottom right

The red lines on the left in the scene are a waypoint route created with RAIN, which designates a point-to-point path the player can go. The purple one is a network of waypoints that can be connected or disconnected in any fashion. This network can do pathfinding based on the navmesh RAIN creates, and will attempt to get to the nodes while walking around obstacles.

That’s the theory anyway. I had trouble figuring out how to connect the AI behaviour and the patrol routes together in the behaviour tree. I discovered that the system RAIN has created doesn’t allow for ‘drag and drop’ of the waypoint routes, rather you have to type the name of the route in (case sensitive) and RAIN will search the scene for it.

After this, I ran into another problem, which was getting the character to move. The wiki documentation only said that the move behaviour takes a location from a vector location or a node location. No mention of how to use it with the array of locations like I have. I ended up discovering (through the files of an example project) that you have to define a location variable in the waypoint behaviour (both of the red and purple ones) then use that (case sensitive variable) within the movement. But don’t use quotation marks like you did with allocating the waypoints, as that will throw a null error!

working2
The AI will randomly decide between two waypoint paths and two other isolated locations

After this grinding of face on sandpaper experience, I finally managed to get the player moving between points.

Once you broke through the completely unintuitive methods (that uses none of Unity’s established methods of allocating location variables), RAIN is quite a neat piece of software. You can change the speed, the direction the character looks, how close or far you can be from the node before changing behaviours.

The only thing I haven’t figured out yet, is stopping the character from looping within the behaviour. I imagine I can use a sequence to override the behaviours at some stage.

I only wish that the tree branches out top-bottom instead of the left-right in the image. Will expand on the behaviour to see how much more complicated behaviours take to learn.

 

One thought on “Experimenting with RAIN

  1. m88's avatar
    m88 says:

    Thank you for the auspicious writeup. It in truth was a entertainment account it.
    Look complex to more delivered agreeable from you!
    However, how could we communicate?

    Like

Leave a comment