Next Broadcast

untitled city defense game: graphics and multiplayer

kellswhere GameDev DK30 New Year 2023 0 0

Description

Can currently expand into regions and build resource buildings there, but the graphics are very abstract. I’d like to add more realistic terrain and building graphics this month. Ambitious to say the least, but my stretch goal is getting basic multiplayer running too.

Recent Updates

kellswhere 2 years ago

Quick update for the live review. I didn’t get terrain working fully over the weekend, but I did figure out texture arrays and blending in Unity shaders, which is pretty cool!

kellswhere 2 years ago

Going to post here to wrap up March. I did not have a very productive second half of this DK30. I have made a lot of progress understanding shaders in Unity, which I’ve wanted to tackle for awhile now. I haven’t gotten terrain textures working yet, though. I think I’m close, so I’ll make a push to do it this weekend, and continue posting occasional updates here if the site stays up after March.

kellswhere 2 years ago

Some background first. My game is a colony-defense citybuilder somewhat in the tradition of They Are Billions. It takes place on an irregular grid of cells. Game logic uses ‘cell’ as the fundamental unit of positioning; you order units from cell to cell, select a cell to build buildings, and so on. Each cell can hold ~2-4 buildings. (Most RTS games aren’t like this, of course. It’s a new thing I’m trying out!) I’m working in Unity.

Here’s what it looked like at the start of March, with abstract polygons and no visuals for buildings: My goal for the first two weeks of this DK30 was to upgrade the graphics. Specifically, I wanted to draw terrain with textures and elevation, and add some sort of building visualizations.

I generate the irregular cell grid as a Voronoi diagram. Turns out rendering heightmaps is not straightforward on irregular terrain! Here are the things I actually managed in the first two-and-change weeks:

  • Wrote “subdivision” tools that takes triangles or quads and fill them with smaller triangles that are approximately evenly spaced. Specifically, I wanted to subdivide while controlling the number of vertices produced on each edge. I wasn’t able to find anything about that specific problem online, so I rolled my own. It assumes at least two edges of the quad or triangle have the same vertex count, but that’s enough for my purposes. I also updated my mesh generation tools to be generic in vertex data (no more dummy UV coordinates!) and to allow me to reuse vertices when connecting different meshed regions.
  • Wrote a DCEL implementation to track connections on the Voronoi cells. I would highly recommend this, by the way. My first attempt used a simpler data structure, but it ended up being harder both to use AND to instantiate! Using the DCEL has been a dream.
  • Adjusted Voronoi vertices to lengthen small edges, which had been causing several annoying issues. I used the approach described here by the excellent Amit Patel. I prefer the boxier shapes that pure Voronoi cells tend to take, but we’ll go with this system for the time being.
  • Wrote cubic interpolation tools to make smooth cell transitions. I did not expect to download a linear algebra library to do elevation rendering, but it looks like that’s how you do cubic interpolation, so here we are! I also ended up writing a polynomial class and auto-differentiator so I could specify polynomials and fit them automatically. This is not the most CPU-efficient way to do heightmaps, but it was a lot more fun than differentiating by hand and then typing in the equations. It also allowed me to iterate quickly on different polynomials and constraints.

Now, here’s the result: No textures and no building graphics, but so it goes! It felt really good to get this far, especially in the face of a pile of unexpected complications. I’m afraid I don’t love the end look, though - I’d like it to feel a lot more natural, without such obvious edges and corners. I had hoped cubic interpolation would handle some of that, but it appears to have mainly just rounded the edges a bit.

Some ideas I may investigate later:

  • Increase the spacing between the flat parts of cells.
  • Adjust vertices after the fact to ‘erode’ them into more natural shapes.

For now, though, I’m going to adjust my goals for the second half (“half”) of my DK30: textures by the end of week 3, and rudimentary building visualizations by the end of March. I’m also going to try to make smaller, more regular updates here.

Estimated Timeframe

Mar 1st - Mar 31st

Week 1 Goal

terrain rendering; rudimentary buildings

Week 2 Goal

buildings

Week 3 Goal

multiplayer lobbies and chat; start on multiplayer gameplay

Week 4 Goal

multiplayer gameplay

Tags

  • unity
  • citybuilder
  • colony defense
  • procedural content