Categories
Virtual World Building

Llama Drama Dev Blog – Llama State Machine

This thing has given me so much trouble over the months. A previous project I did also had a state machine so I thought I had learnt somewhat from that one. Apparently not. I struggled with this thing. What started as four states and a bunch of item interactions quickly became nine states with numerous conditions between them. It hurt my brain to think about it so I spent a few months just writing it down on paper with pseudocode so that I could change things easily but still see previous work.

It was also really easy for me to get confused when writing the script to the point where it was easier for me to just start a new script than to try figure out what is missing from the current one, as shown by the numerous similarly named scripts in the adjacent image.

The most confusing part of making the state machine was figuring out how to do it. Having only made a very simple one before, my immediate thought was call each state as separate functions in the update function. I then got confused about how I would transition between each state and just everything. The other idea was to put absolutely everything in the update function but I figured that there would be a lot and putting it all in the update function might not go very well. It would also mean I’d have to plan around the function getting called every frame, and I couldn’t just make the code wait before executing the next line. The other option I was shown was to make classes for each state and fill the classes with the code for each state. I tried each of them and got confused every time. I thought making separate classes for each of them would be the best way to go, if only I could wrap my head around it. I understood it in class but then I went home to try and just couldn’t understand anything. So that’s a no go. I couldn’t figure out how I would go about having each state as a function, so that was out. Leaving me with putting everything in the update function.

States as Classes
States as Functions
Everything in Update()

The state machine ended up with ten states, nine of which are currently in use. Idle, Searching, Advancing, Retreating, Annoying, Attacking, Spooked, Stunned, Trapped, and Grabbed. Grabbed is not in use currently as we decided to leave it out, but it would be for when the player picks up the llama. Idle is when it’s doing nothing and is used as a transitional state. Searching is when it gets a random target to go to. Advancing is when it paths to its target. Retreating is when it runs away and paths to a random hiding spot to then check if there is a line of sight with the player before teleporting away. Annoying is the task version of attacking – the llama takes one of the items required for the player to complete a task. Attacking is for the llama to do some sort of damage to the player or specific items from the fabricator. Spooked is when a thrown item or a specific fabricator item effect makes the llama run away but come back to the same task target or fabricator item target. Stunned keeps the llama from doing anything until the duration is over. Trapped is similar to stunned only it requires a physical trap object to keep the llama there.

There’s not much else to say about the state machine. Despite how big and important it is, it’s pretty much just the states, how to transition between the states, and any interactions with other objects in the game.

Categories
Virtual World Building

Llama Drama Dev Blog – NavMesh

The best way to have a state machine path around an environment in Unity, I found, is by using a navmesh. I had briefly looked into them in a previous project, but due to the tutorials I was following leaving out a lot of the required code and details as to how to get it all to work, I didn’t go ahead with using it. So this was my first time using a navmesh.

I spent quite a bit of time just watching videos about how they work and the different components just to get used to them. I found Brackeys’ “Unity NavMesh Tutorial” series and LlamAcademy’s “AI Tutorial Series in Unity” on YouTube particularly helpful. I also found it pretty funny that I found a channel called LlamAcademy that has an entire playlist about navmeshes when I’m needing to learn about navmeshes to make a llama move around.

I started testing how navmeshes work in my test project, starting with a simple point and click navigation.

Point + Click Navigation
Point + Click Script

After that it was pretty easy to set up a navmesh. If an object isn’t going to be moving then set it to “Navigation Static” in the “Navigation” tab, check if you want to generate offmeshlinks for it, choose from the drop down if an agent can path on it, and bake.

Llama Drama NavMesh

I did see in several videos that you can use downloadable navmesh components instead of the built in navigation tab and it looks like they have much greater flexibility. I would like to try use them in the future, particularly for offmeshlinks. The built in navmeshlink component takes a start and end gameobject for it, whereas the downloadable components can designate entire areas to link between instead of the position of specific gameobjects.

The navmeshagent is pretty straightforward to set up too. It is annoying, though, that it allows you to make custom agents besides the default humanoid, but doesn’t like when you do. We had a lot of issues with custom agents where they would work fine for a while and then out of the blue Unity didn’t like them. We ended up having to go back to the default humanoid and change the values of that around, which isn’t such a big deal with just one agent in the scene, but if we had multiple different types of agent then it would’ve been very troublesome.

In the state machine, the llama teleports from one location to another when spawning into the office and running away to hide. Turns out, navmeshagents don’t like it when you use transform.position to set their new position. Sometimes it works, like it did for me for months, but at some point it will probably break and never work again. So use navmeshagent.warp() instead. It does the exact same thing only the agent will like you more for it. I haven’t had a problem with the teleport since. Just make sure you’re warping onto a navmesh.

Unfortunately, a problem has come about this last weekend. So navmeshagents have multiple coloured arrows that point in directions corresponding to the values of those arrows. One such arrow is blue, and the blue arrow points in the direction of velocity. The direction the agent is applying force to move is the direction the blue arrow points. Our problem is that sometimes when the llama spawns into the office workspace, that blue arrow is pointing straight up. Consequently, the llama doesn’t move when that happens because there’s no velocity being applied in any other direction, and the agent won’t leave the navmesh. We didn’t have this problem before and we have no idea how to fix it. The internet is not very helpful for this problem. Sometimes the arrow will point in the direction it is meant to, but it will flicker, and the agent with slowly move in that direction. It will constantly change speeds but never reaches the set speed it should be using. We’ve tried asking lectureres for help and they’ve given suggestions, but they haven’t worked either. So we’re stumped. I have no idea how to fix this problem and I’ve been trying all weekend to no avail.

Categories
Virtual World Building

Llama Drama Dev Blog – Llama Design

I didn’t know what I wanted the llama to look like so I started by drawing the outlines of real llamas to help me get the general shape so that I could then draw miniature stylised llamas.

I wanted to see if I could draw something cute but recognisable.

Out of the two drawings above, I drew the darker lined llama first. It was too realistic and not cute enough for my liking, so I drew the smaller one next to it. This one looks much closer to what I want with its size and proportions but I felt that it wasn’t recognisable as a llama. It did make the idea of short legs more important for the design though.

After not much success, I started creating AI generated concepts of a llama using Dream by Wombo and DeepAI, with varying degrees of success. As our game is set in a post-apocalyptic world and the llamas have mutations, it meant the AI generators could really go ham with what we could accept. And they did. The prompt “short legs” apparently meant three legs. Below are a few examples of art generated by the AIs, and you can find more here.

We ended up picking a more casual design that we wanted to take from but with some adjustments. The full body image below was our choice, however, we decided to shorten the hairdo. It is also an example of “short legs”. I didn’t really like the eyes though, so I decided to change them to those of the image next to it.

The idea of a derpy tongue hanging out was also suggested. The adjacent image is what I drew using the group feedback and AI images as references. I added the mismatched eyes as my own idea and we all like it. It’s cute, it’s derpy, and it’s strangely menacing.

I started working on the character rotation of the llama, drawing front, back, and side views of it. The front and rear views are alright but I really didn’t like the side view I drew. It looks more like a dog than a llama, and that’s after changing different body proportions to make it look somewhat comfortable on the eyes. I hate it. I needed to change it before I modelled the llama.

Front View
Rear View
Side View

I went back and redesigned the side views of the llama. They don’t quite line up with the front and back views but I think they are close enough that I can mess around during the modelling to find what works best for the overall model.