Cornucopia Raw Dev Log #2: The Beach is Now Part of Your Farm Area
So I'm back for the second dev log! The first one on the environmental vegetation optimizations did surprisingly well. I'm very happy about that :)
This one's got a lot of stuff in it. The big gameplay thing is you can now place your refining fixtures (furnaces, saws, sprinklers, tumblers, etc) in the new oceanic area connected to the farm. I was originally not going to allow it because the ocean zone is just so large and I thought it was beyond the scope of having such a huge area with all placeable terrain.
But I decided to do it anyways due to breakthroughs with performance, and figuring out the game can handle more than I thought. Originally this area was planned by the modeler and me as being purely decorative, and we only hoped that maybe somehow it could all be placeable. Happy to see that we pulled it off!
Making the grid system so much larger, while still compatible with old save files from early access players, was a lot of careful coding. I also built an entirely new tool for painting the terrain, marking off the tiles where you can't place stuff because there's environmental things in the way. Rocks, flowers, cliffs, water, that kind of thing. A lot of work, but it's done now.
The New Background
The modeler sent over the finalized version of the new farm zone background a little while ago, and it's pretty sweet. The old background was basically just a flat image back there. This new one has a bunch of hand-painted layers stacked at different depths. Distant snow-capped mountains way in the back, green mountains with cliff faces in front of those, an oak treeline, and then a dense pine forest up in the foreground. Everything is pixel art and hand-painted by him. There's like 5 or 6 depth bands in total. The farthest mountains are this pale minty color because they're supposed to be so far away. You can kind of see little dog and face shapes in the cliff rocks if you look for them.
Getting it to work properly with the camera was a bit challenging honestly, because the perspective shifts around a lot as you zoom in and out. My first attempt was a calibration tool where I'd dial in exactly where the background should sit at every zoom level, but I ended up scrapping that whole approach. What I did instead was just angle the tree line downward and extend it way further. So when you're zoomed more top-down, you're mostly seeing trees. When the camera tilts more paper mario style side-on, the mountain line shows through behind them. Way simpler than trying to reposition everything per zoom level.
Waterfall Blending
I also improved the blending where the waterfall meets the river at the top, which was looking a bit rough before. It used to have kind of a hard seam right where the waterfall mesh started and the flat river water ended. Now there's a custom material on the waterfall that fades into the river surface instead.
Rebuilding the Placement Grid
Okay to back up a bit, the game already lets you place refining fixtures out in the open on your farm, anywhere you want. Furnaces, saws, sprinklers, scarecrows, tumblers. Anywhere there's a flat tile or a slope that isn't extreme, you can place stuff down. (That includes planting fruit trees, berry bushes and other stuff too.)
With the new ocean zone connecting to the farm, I wanted the same thing to be true down there. Same rules, just in a much bigger area. Drop your furnace on the beach if you want, same as up top.
The problem is the old placement system wasn't really built for an area this big with this much decoration on it. And it wasn't really built for handling old save files from early access players either, since they already have their whole farm laid out on the old terrain shape, with soil values and vegetable plant positions saved. So I had to redo the whole thing from scratch to handle the changes as well as old save compatibility. (btw, doing development with having to worry about saving/loading compatibility and translations makes everything harder, so I recommend new devs think about that.)
I also had to build a new tool in the editor for marking off the spots where the player shouldn't be able to place stuff. Basically it's like a painter tool where I paint red tiles directly on the terrain. All the decorative rocks, flowerbeds, stonework, water, cliff edges, stuff like that gets painted red on a per-tile basis as the game is set up. I can paint from top-down view for big areas fast, or switch to in-game perspective view for the fiddly spots where I need to nudge tiles around individual props. I switch back and forth a lot.
The tool itself is done now, and I've also finished hand-painting all the blocked spots across the whole new terrain, which was honestly something I procrastinated a bit on.
Another thing I had to fix was the actual blue grid line visual itself due to the new varied terrain. When you're in placement mode, the game draws these blue grid lines on the ground so you can see which tiles are available and which are occupied (in red). Technically it works by projecting a decal downward and reading the depth buffer to figure out where the ground is. On the old mostly flat terrain that worked fine. But on the new terrain with all the cliffs and waterfalls, the grid was drawing on everything including cliff faces. Not exactly professional.
The fix was a few things. The original shader was asking the terrain what direction it was facing, and using that to decide where to draw the grid. The problem was the terrain shaders were kind of lying about it. They were writing "I'm flat" into the G-Buffer even on cliff faces, because of some weirdness with how terrain normals work in Unity. So no matter how much I tightened the angle cutoff, the grid still showed up on the cliffs, because the number it was checking against was garbage.
What I ended up doing instead was making the shader figure out the actual slope on its own, by looking at how the world position changes from pixel to pixel across the screen (ddx and ddy derivatives, for any shader people reading this). That gives you the real slope of the ground at every pixel, no matter what the terrain shader claims. Then anything steeper than about 30 degrees from horizontal gets cut off. I also shrunk the height of the projector box so it doesn't reach as far down vertically. There's a smooth fade near the cutoff angle now so the grid doesn't hard-clip at the edge.
Warp Zones
I also set up a bunch of warp zones connecting the new terrain to the other zones around it. Bottom cave up to the top cave, farm down to the beach, into town, the junction area. Makes the whole map feel way more connected instead of a bunch of disconnected zones. Sparkly indicators included so you know where they are.
The funny part is how I was actually measuring where the player should spawn on the other side of each warp. Every warp has to drop you into the destination zone at a specific spot, facing the right way, and not clipping into a wall or a rock. So I needed like a reference body roughly the size of the player to stick in the scene while I was lining it all up.
I ended up just using Rufus the farmer's sprite for this, which is kind of a weird technique but it worked pretty well! Literally just placing Rufus at the landing spot in each zone so I could eyeball whether the size and position and angle all felt right. He's the perfect size for it.
Farm Animal Pathfinding
One more thing I wanted to mention was the farm animal pathfinding. All your farm animals, like your cows, your chickens, your horses, whatever you've got following you around, they use A* pathfinding to keep up with you. Basically a grid layer that sits underneath the whole terrain and says what spots are walkable and what spots aren't. Each animal figures out a path from wherever it's standing over to wherever you are on its own.
The problem is the old pathfinding graph only covered the old farm area. So when I extended the world down into the ocean zone, the animals would follow you right to the edge of the farm and then just stop. Sit there and watch you walk off into the ocean without them, which was kind of sad.
So I rescanned the pathfinding graph across the whole new terrain. Farm, junction, ocean zone, all of it. Now the animals can trail you all the way down to the beach without getting stuck at an invisible fence somewhere.
The other thing was that big decorative props like the cliff rocks, thick clusters of trees and stuff like that, they don't automatically block the pathfinding on their own. Each of those big props gets a "Pet Obstacle for A*" marker on it now, which carves out a non-walkable zone around the prop when the pathfinding graph bakes.
Now the animals route around all that stuff the way they should, and they can follow you anywhere in the new terrain without getting stuck. Much happier about how they behave now :)
-david
Full devlog with all screenshots: https://cornucopiavideogame.com/devlog/junction-grid-blocker/
https://store.steampowered.com/app/1681600/Cornucopia/











