Learn You a Game Jam Day 3 devlog


I know I said yesterday that I would just keep going forwards and screw the issues the game was having but I woke today realizing that I couldn't stop thinking about the issues all night and I couldn't stand it. I had to fix them.

So day 3, good news, I fixed a lot of the problems I was having!

Again, I cannot stress how important Debug.Log() is. I put it EVERYWHERE trying to pinpoint where my issues were stemming from. Eventually, I found a function that made no logical sense. It was taking in an argument but wasn't using that variable anywhere? Something's very wrong with it. Anyway, long story short, I fixed it, it's all good... I have maybe one miiiiiinor problem but it's just a UI thing, it's fine.

But that's not why you read this, you want to know how it all works.

Pathfinding

This was admittedly the most intimidating part for me, especially on a tilebased isometric plane with different heights. I'm not even sure I fully understand it still, but I'll try to explain it the best I can.

First, you want to check between the tile you're starting at vs any potential pathings around it. Height or movement limitations are not handled by this and instead will be handled by the individual movement system.

directions = 4; //North, East, South, West
Queue<Tile> checkNext = new Queue<Tile>();
//since i starts at 0, i will only hit "0, 1, 2, 3" which is 4 items so i needs to be < 4
for (int i = 0; i < directions; ++i) 
{
    Tile next = GetTile(tile.position + direction[i]); //get the potential next tile
    //if the next tile is not occupied and it's within walking distance, continue
    if (next == null || next.distance <= tile.distance + 1)
        continue;
    if (addTile(tile, next)) //checks if the potential path between the two tiles is successful
    {
        next.distance = tile.distance + 1;
        next.prev = tile;
        checkNext.Enqueue(next);
    }
}

Don't copy this because this was a really simple and broken down version of what I have. If you want to know more, follow Liquid Fire's tutorial. But essentially, what you want to do is check one tile's surrounding 4 directions, and then add them into the queue if you can walk on it, and then once that's all done, go through each of the checkNext tiles after that, rinse and repeat. It sounds tedious (because it is) but we're not the ones manually making the calculations thankfully. After that, you pass that list down somewhere to be used.

Also, for regular walk movement, I found this to be very intuitive:

// Skip if the distance in height between the two tiles is more than the unit can jump
if ((Mathf.Abs(from.height - to.height) > jumpHeight))
    return false;
// Skip if the tile is occupied by an enemy
if (to.content != null)
    return false;

Fun little thing I learned

Also! I learned something on my own without the tutorial because it's old and one of the functions was outdated. CreateAssetMenu is a fun little thing that allows you to modify the Unity Interface itself. It creates an asset with all the variables under the class it's on:

[CreateAssetMenu(fileName = "NewAsset", menuName = "Assets/Create/ANewAsset", order = 1)]
public class NewAsset: ScriptableObject
{
    public List<int> listOfNumbers;
}


and viola! You can now go into Assets > Assets > Create > ANewAsset. I could probably remove the extra Assets menu entirely but that's a minor issue. Anyway..

Command System

Understanding the UI system was also new for me. There's a lot to learn; the most I knew how to make previously was a button with an OnClick listener, now there's "Fire1", "Fire2", "Fire3" listeners for mouse clicks as well as the "Horizontal" and "Vertical" listeners for up/down left/right.

These are all pretty simple.

void OnMoveEvent (object sender, InfoEventArgs<Point> e)
{
    Debug.Log("Move " + e.info.ToString());
}
void OnFireEvent(object sender, InfoEventArgs<int> e)
{
    Debug.Log("Fire " + e.info);
}

And none of that really helps with the command system, but it does help to know how to make Lists, navigating through them and creating instances.

public void ShowMenu(List<string> options)
{
    for (int i = 0; i < options.Count; ++i)
        {
            AbilityClass ability = Dequeue();
            ability.name = options[i];
            menuEntries.Add(ability);
        }
}


Essentially, when you break it down, it's just a big ol' list and depending on how you handle it, that's the menu! Or whatever your panel needs to be.

I think the lesson of the day is that things are a lot less intimidating once you break it down. In other news, using itch to write a devlog is so broken, do not recommend.

Get Monster Tactics

Leave a comment

Log in with itch.io to leave a comment.