Categories
Virtual World Building

Llama Drama Dev Blog – Target Randomisation

One of the main jobs the llama needs to do is to get a target and path to it. But we don’t want it to be the same target every time, so we want to randomise it. And when the target has been dealt with, we want to get a new target that isn’t the previous one. By itself it is pretty simple. Make a list of targets, randomly pick one, and set that as the agent destination. When it has been dealt with, remove it from the list and randomly pick a new one.

Target Randomisation

This isn’t by itself though. There is a HUD for the player that lists the tasks they need to complete. Those tasks are the targets for the llama to disrupt. That list is random every time, with a task appearing third in the list one day and maybe first the next. To make matters even more confusing, that list is full of integers. Somehow the llama needs to take a list of integers that correspond with certain tasks and then populate its own list with the gameobjects of those tasks, then path to one of them, disrupt it, remove that gameobject from its list if it gets removed from the HUD list, and get a new target.

I got around it by giving the llama two lists. One of them gets the integers from the HUD list, the other gets the gameobjects that correspond to the integers in the first list by using a switch case for each integer. In hindsight, it’s not actually as bad a problem to solve as I thought it was at the time.

Corresponding Gameobjects of Integers

The other problem was the llama lists weren’t actually getting any of the tasks from the HUD, and the HUD wasn’t even filling its own list fully. Colin and I thought maybe the HUD script didn’t like referencing the llama’s script so we tried having the llama script reference the HUD script, but that didn’t work. We spent hours on a call trying to figure it out but nothing we did worked. Finally decided to use the download the debug tool and attach it to Unity as I remembered I could stop the code executing to see what happens. It’s been a few years since I last used this tool so I didn’t think of it for a while. We put in a bunch of breakpoints and found that it was skipping some, but we couldn’t figure out why it was skipping them. It would start up, add two items to the list, then skip. The next time it would start up, add one item, skip. It was inconsistent, but that also made me think that it was a specific thing that was triggering it. I decided to use step over instead of breakpoints to go line by line and see the results of variables. Turns out that when the script was removing variables “task1”, “task2”, and “task3” from the list “tasks” if any of them were null it wouldn’t know what to do and would skip to the next frame. So a simple gameobject not being assigned in the inspector turned out to be breaking the entirety of the game. After adding the object into the slot in the inspector, everything ran smoothly and all the lists filled up nicely.

Debug Mode

Leave a Reply

Your email address will not be published. Required fields are marked *