DEV Community

Rising Tail
Rising Tail

Posted on

Devlog #3: Frustrations and math stupidity

Last time I talked about the concept of modular building. You can check the links above if you missed it. As I set out to do the actual implementation in game, little did I know that this week would turn out pretty frustrating.

First of all, it lead me to redesign a component system a few times because I wasn't happy with it. Then it revealed that the modular thinking might not be such a good idea for gameplay. It looked good in the mockup stage, but some parts of it doesn't actually make sense. So I decided to take a break from that until I've figured out how to solve it.

The next big thing on my list was getting started with what's going to be probably one of the most fundamental mechanics in the game: transporting items on conveyor belts.

In theory it sounds easy. Spawn an item on a belt and move it forward. When it reaches the end, check if there's another belt in front and have it take over the item.

Yeah.. about that... I've probably spent 20 hours on this, and it still isn't perfect. I had major problems figuring out how to sync the speed of the moving items with the speed of the belt. The belt tile is an animation of 4 frames with a frame speed of 80 ms. My naive thinking had me believe that if I calculated how much a single pixel "moves" in one ms in the belt animation, I could just apply that to move the items on top of it. Apparently not. No matter what I did, it was either too slow or too fast. This is where my lack of math knowledge (and gamedev experience, I guess) really showed. One of the issues (or so I assume) is that the animation uses an accumulated delta time value to determine which frame should be active at any given time, whereas the belt entity uses a proper delta time. So it's not quite the same thing. I've spent hours just looking at numbers, trying to come up with an algorithm that works in all cases (because it would also have to work if I changed the speed of the belt). In the end I settled on using a seemingly magic number that makes items follow the belt almost perfectly. Over a distance of 15-20-ish tiles they will start to lag a little behind - maybe 1-3 pixels or so.

I know Factory has perfected belt and item movement, but out of curiousity I fired up Mindustry to see how it works there. To my big surprise and somewhat relief it has the exact same problem. Items seem to sync with the conveyors, but over longer distances it starts to show that there's a small difference. That eased my mind a little. And I left it at that.

So, a week of rewriting lots of code and feeling stupid for not having math knowledge to figure this out. Not the best of weeks, but..

On the upside, I have spent more time in Aseprite working on some of the assets. I think I've decided on a sort of low-res art style, for now at least, because that's basically the only thing I can do myself that doesn't look like crap. I'm testing a sort of abstract concept with a basic template for units and then using various colors and shapes on top to differentiate them from each other. I tried drawing something that could resemble a miner, but 32x32 pixels and a pure top-down perspective makes it very difficult. I know I showed some units last time that were more "detailed", but this is much faster and much easier for me, ultimately freeing up more time to do actual programming.

So here it is, a miner unit producing gold ore and spitting it out on a conveyor, animated for your viewing pleasure. Or mine..

Let me know what you think?

Discussion (0)