Hi, Habr. My story begins in January 2019.
My gamemaker and my game developers decided to take on the biggest project in our story, a 2D platformer. No, we haven’t done any FlappyBirds or snakes before, but the amount of work in this project simply demolished our brains. For a start, we abandoned conventional, vertical stairs, and took stepped stairs. We wrote logic for the doors, which could be locked “on the key” and fastened destructible blocks. The moment came when it was necessary to write Artificial Intelligence. As the most experienced of our inexperienced team script, the honor of writing AI fell to me.
I cried in the pillow, not understanding what to do, I was very proud that I would write one of the most difficult mechanics in our project.
Stage 1: finding the path and driving along the path
Stage 1.1: Path Search
Since we will have the main locations not in the open air, but in buildings, we had to do a search for a route among dozens of doors, stairs and rooms. Having thought it over, we decided with the timlid that it is worth making a certain parody of the A * algorithm, where we will have nodes, between which the bot will run. made a test scene, put the nodes, for clarity, hung up on them SprateRenderer'y. What to do next?
With this question in my head, I went for 3 days. So far, one friend of mine has proposed an interesting algorithm when the nodes will be excited, like neurons in the brain.
')
So. There is a node A, near which the AI ​​is located and a node B, to which the AI ​​must come. gave all the nodes their ID and marked the connected nodes to which they will send a signal. Each node had its own boolean variable “isChecked” and the variable “triggeredBy”, in which the ID of the node that “excited” it was stored. So, when node B is touched, it will go through the chain to node A, recognizing all the node IDs that passed the signal. So I got the path from the IDs of the nodes that the bot should go through. If you suddenly do not understand how this works, then I will tell you a fairy tale.
Once Ivan had nothing to do, and so he decided to compile his family tree. Unfortunately, he did not have enough information to translate this idea into reality. Ivan was so fascinated by this idea that he decided that by reaching the main ancestor he would be able to discover his unexpected relatives. Ivan knew where he could meet his father to talk and headed there. His father told him that Ivan’s grandfather’s name was Ivan and told him where to find him. Ivan found Ivan, and he said that Ivan's great-grandfather could have known this ancestor personally, but he died a long time ago. Ivan spent half his life studying the dark arts, but in the end was able to resurrect his great-grandfather. Great-grandfather said that his grandparent was a werewolf and that his body was buried on the edge of three pines. Ivan went there and found a man digging a grave. It turned out that this man - twelve-brother Ivan. Ivan was very surprised that they came to one place, but my brother turned out to be a programmer and explained everything.
- The principle of navigation from my favorite game * name * works here!
- And what is it?
- From each heir one can come to the common parent of the system, if in this system each heir personally knows his parent.
This is the result:

This is an array of int-variables that mean the ID of the nodes that the unit must pass.
Stage 1.2.1: follow the path
I have a list of node IDs, I have a bot. What's next? And then what should move the bot on this path.
Well, I figured this option: the bot reached the node, put a tick, looked at what was next, went to the next node. Made. It worked. I was glad ... But ...
Stage 1.2.2: stairs and their interaction with AI
As one black and white hero said: “Stairs ... my main enemy ..”
It was necessary to determine whether the next node is above the AI, below, or at the level. Depending on this information, it will pass by the ladder (ignore the collision), or climb on it (interact with the collision). Oh, and a lot of nerve cells were killed in this battle with the engine ... I read on the forums that you can arrange everything in layers and in the Edit-> Physics2D tab you can configure to ignore collisions of one layer and the other. It all worked!
It remains only to teach him to open the door. There were no problems.
Total:


Stage 2: Emotions and Replicas
Stage 2.1: Emotions
Yes, we decided to attach emotions ... And replicas.
Emotions will be highlighted by facial expressions and action animations.
Replicas will appear overhead.
Emotions I screwed up in the same breath ... For this, I already made the variable "emotionID", which kept in itself the ID of emotions. But the replicas ...
Stage 2.2: Replicas
For beauty made a separate class Phrases
[System.Serializable]
Made an array of this class. Further, simply depending on the emotionID, put any phrase from the list. Updated every N seconds.
But I decided to go further! For each character, I made a file with the .phrs extension, encoded it with the help of adding X bytes to the byte number of each character in the file. The result was unreadable, unchangeable text. I did something like my own markup, I made an algorithm that takes and, by this markup, translates everything into an array of the Phrases class.
Fine! Everything is working!
I wanted to write a program on a clean sharpe to fill such a file, but here we go to the end of the story.
The end..?
We quickly got tired of the big, unpaid work ... Joining the new coder did not help ... The team collapsed ... The code still lies on the Unity cloud.
Of course, the idea to continue the project began to emerge not so long ago, but already with further monetization ... If something works out, then I, perhaps, will write the whole development history. But this is where my story about the beginner scripter and AI ends.