Month: November 2019

Week 10 – Turns!

Week 10 – Turns!

I finally made some much-needed progress on turn order this week, and I polished up the ortho view.

(I apologize for the relative lack of images – I will update with those ASAP, but I can’t get pictures off of the Pixel for the moment.)

I started by doing something a little simpler to ease into it – I added zooming & scrolling to the main orthographic view. This was fairly straightforward and only took a couple of hours. There were a few problems here and there, but most had fairly trivial solutions once I diagnosed them. Scroll bars didn’t like to scale properly, as an example – I don’t really understand why this was the case, but it’s not like it was a challenging fix. I spent more time trying to handle issues with object placement: the grid isn’t centered at (0, 0) in ARCore, and mixing that with scaling meant it was extremely easy for the orthographic view to find itself centered nowhere near the grid.

I have also taken steps to greatly simplify my network code – and it looks like it’s paying off! I stripped almost every method that wasn’t either meant to be an RPC call or a helper, and made sure that any logic more complicated than changing a couple of variables based on one input was handled entirely by the host. I also simplified method parameters – previously, I had been using parameters that were too complex to work with, but now they’ve been reduced to a single string at most.

A before and after of how characters were added. AddCharacter was used in the same situation as AddCharacter_New. AddCharacterStatic is used in the same situation, but only for non-host players.

Here it is in action:

Super exciting stuff, I know. I also managed to get it set up such that a player can no longer drag their character around outside of their turn, but can still take steps to plan their turn, such as viewing characters’ movement radii.

While it may not seem that big, this is massive for me this week, especially since the expo is only 8 days out. The last things I need to do now are:

  • Clean up Touch Management a bit. Due to (I believe) the toll AR takes on devices, touch management can be spotty in AR. I think the phone might be missing when a TouchEnd event should happen at times, and other times I think it just loses track of the finger.
  • Multiplayer AR. While Cloud Anchors would be ideal, I may have to settle for getting augmented images working again. It seems like a consistent way to not have to worry about actually networking the grid while ensuring that it is as aligned as possible.
  • General polish (sir). There are smaller issues here and there – AoEs don’t scale properly in AR thanks to the grid scale slider, if it’s not you’re turn the picture-in-picture doesn’t pop up until you let go, highlighting tiles while dragging doesn’t work anymore, etc. Mostly small things that I can go without, but should also only take a matter of minutes to fix.
Week 9 – Almost There?

Week 9 – Almost There?

This week was also a little messy, but I did get some stuff done. Unfortunately, I was unable to get either of my main goals from last week done. I opted to focus less on Cloud Anchors this week – after reading more on them, they seemed difficult to implement using Photon, and I wanted to get my other issues in Photon solved first.

Which brings me to my first point: I left off last week in an ugly place with regards to networked multiplayer. I made a little bit of progress this week on that front – my code was looking more than a little al dente, so I decided to first take a few steps back and untangle the noodles a little bit. Before, I had each client processing the turn changes, but now I made sure that as many of those actions as possible fall to the host, which then tells the other clients the outcome.

Thankfully, this fixed the turn-sync issue – both clients now agree on whose turn it is! However, this showed me that the host seemed to believe that it was the owner of each player in the game, though this was a fairly easy fix. I left off here this week with it appearing that ending a turn doesn’t actually rotate through the turn order – very concerning. However, I spent a lot of time and energy on this for this week, and I felt like I needed something more tangible.

So, I went back to AR. I’d made so many changes since I last was working on my AR implementation that I could no longer just drop my code into an ARCore scene and watch it work, so I had to make a surprising number of changes to get back to that environment. It didn’t help that Unity decided that it doesn’t want to work with ARCore’s Instant Preview, so I have to build to a phone to test anything in AR now and I don’t have access to the editor at runtime – which was a considerable slowdown, but not a total blocker. Now, I have it working in AR, though it’s not perfectly stable; touch and drag registration is finicky, but when it works, it looks good! Shout-outs to my contact who lent me a Google Pixel 2, which has proven to be magnitudes more consistent than my own phone with ARCore.

Detected floor…
There we go.
And voila!

For now, this is absolutely acceptable! It’s not perfect, but it works well enough for now. I’ve gotten used to adjusting my touch management on a nearly-weekly basis by this point, anyway. As you can see, I also added a scale slider – this doesn’t work perfectly, and its range is a little crazy but I’m happy with it as a quick-and-dirty implementation of a much-needed feature so far.

For now, this is absolutely acceptable! It’s not perfect, but it works well enough for now. I’ve gotten used to adjusting my touch management on a nearly-weekly basis by this point, anyway. As you can see, I also added a scale slider – this doesn’t work perfectly, and its range is a little crazy but I’m happy with it as a quick-and-dirty implementation of a much-needed feature so far.

In addition, I decided to implement another AR aid feature: a full orthographic view. Many games that use a tile-based grid will offer a minimap, such as in the Fire Emblem series:

Fire Emblem: The Blazing Blade, for the Game Boy Advance

Since I made the Picture-in-Picture view a few weeks ago, a full orthographic view of the entire map seemed like a solid move. I ran into several issues here: Touch management caused more issues, scaling and camera placement was messy (🍝I currently have two scale factors🍝), and swapping between the two views wasn’t as straightforward as I would have liked, but it turned out alright:

Ft. Detected Plane

Ideally, this view would be able to zoom and pan, but I thought this was a fine stopping point for this week. I could also continue to show the AR view in the background, but that might just be visual noise.Going forward, I’ll set myself some easier, smaller goals – clearly I need to be doing that more often. Specifically, I’ll implement zooming and panning for the Orthogonal view. I already have set up a basic UI for that, but haven’t implemented functionality. On a larger scale, I need to figure out the turn order issues. I think for that I may need to completely restructure my turn code, but now that I have a better idea of how to avoid the pitfalls I ran into previously, I’m confident that it can turn out alright.

Week 8 – More Networking

Week 8 – More Networking

This week was rough. Nothing really went my way, and I struggled through a bunch of issues with little resolution. I’ll start with the good: I made a small fix to touch management that makes dragging work properly when the finger isn’t positioned over the grid. It used to be that, if you were not touching a grid tile, lifting up your finger would cause the game not to register that you stopped dragging. I also had a small issue where, if you were dragging one object and held it over another draggable object, the dragged object would be swapped.

So that’s the good news. My initial plan for this week had been to start moving back towards AR and to implement more rules in a networked environment. Starting with AR: for whatever reason, the Augmented Images feature of ARCore, which I was looking into using (aligning the grid onto the map seems difficult over a network otherwise), stopped working. Even the sample scene stopped functioning. I spent a couple of hours trying to debug this while also trying to write code that would work for my use case, but ultimately came away frustrated. I’m looking into using Cloud Anchors now, as I believe they will also function well, but I will need to test them. Aligning the digital and physical grids may be difficult for users, but I’m not super concerned about that for now.

After that, I decided to work on implementing initiative and turn order. This would likely not be difficult in a local setting, but over a network this is proving extremely difficult. I wanted to start basic: Rolling initiative takes no user input, it just randomly selects a number 1-20 and stores an [initiative, character] pair in a dictionary, using the initiative as the key. The game would then count down initiative, then resets the round when it gets to initiative count 0. I’ve run into many issues with this. One such issue is synchronizing initiative values: at first, I tried to add a photon view (which watches a component and synchronizes specified values) to the EncounterManager object and have it watch the initiative dictionary, but it couldn’t watch the dictionary due to the Character type. This required some mild retooling, but wasn’t super difficult.

Additionally, for whatever reason, turns don’t seem to sync properly, and when the game starts with two players, each client consistently says that it’s the other player’s turn.

How the screen looks before the encounter begins
The text in the bottom right should both say the same thing, and one of the clients should have an “end turn” button on the bottom of their screen. 

Around the time I started on this, my builds also stopped communicating with an instance running in the editor. I tried setting up a symlink so that I could have two editor instances running on the same project, but I couldn’t get that working either. This made debugging extremely difficult. Ultimately, I spent a lot of time wrestling with these issues this week. This has been frustrating, to say the least.

For next week, I’m hoping to meet with a local AR company to discuss ARCore a bit more, and I’m going to keep working at the initiative issue. I think these are both vital to the project, and I hope to make better progress next week.

Week 7 – Networking

Week 7 – Networking

This week, I started work on networking within Unity. At the recommendation of my adviser, I used Photon Unity Networking (PUN) to achieve a networked connection across game instances. This week is fairly light reading, as I don’t have a whole lot to show, but I think I’ve made decent progress nonetheless.

This process of getting networking to work in a basic form was straightforward, as Photon has a good official tutorial. I had two characters instantiated in the game world in just a couple of hours. Of course, there was nothing to determine which player could move which pieces, so I had to work on that. This proved harder than expected – at first, I made it so only the owner player could move their piece – but what happens when the DM needs to move it for them? Then I made it so the DM could move anyone’s character… but this caused a pretty major desynchronization where a player wouldn’t see their piece move unless they moved it.

I thought that would be an easy fix at first – I made it so that ,when the DM would try to move any piece that wasn’t their own, ownership would be transferred to them for the duration of the drag, and then when the user releases their finger, ownership would be transferred back to the original owner. This took a while to fix, and seemed pretty important, but eventually I got it to a more consistent point, shown below.

Only the left screen is actually the DM.

As it is, if you’re not careful, the players can still be desynchronized, but at this point I believe that is an issue with my touch management that I will have to fix later.

Somewhere in here I ran into a fun little issue where, if I closed the game without pressing “leave game” first, the Unity Editor would crash, and then get stuck in a crash loop where it would crash when I opened the project – that was a mess and a half, but the fix ultimately just wound up being to try and snipe another scene into the editor before Unity could load the lobby scene, but I was worried I was going to have to nuke the project and redo my setup for a while and wound up not having to – so that’s a happy ending, I guess?

I’ve also added functionality for a player occupying a tile to count as rough terrain – this was nothing huge for a single user, but in multiplayer took a little bit of extra learning. Thankfully, the solution was also straightforward for that – Photon’s RPC calls are easy enough to use.

Overall, I didn’t make a whole lot of tangible progress this week, but I feel like I made significant strides in understanding Photon and networking, and hopefully I’ll be able to springboard off of this week into a lot of meaningful work.

Theme: Overlay by Kaira
Ann Arbor, MI