All Dev Logs

Raw Dev Log #2: The Beach is Now Part of Your Farm Area

So I'm back for the second dev log! The first dev log on the environmental decorating optimizations did surprisingly well. I'm very happy about that :)

In-game screenshot of the player wading through the river out behind the farm, with the red barn and a log cabin visible on the grassy bank above
Wading through the river just behind the farm.
Wide establishing view of the full map showing the farm at the top of the cliff, a waterfall cascading down the cliff face into a pool, and the new beach and ocean zone spreading out at the bottom
Top to bottom: the farm up top, waterfall down the cliff, and the new beach zone below.

This one's got a lot of stuff in it so there's a jump menu down below if you just want to skip around. The big gameplay thing is you can now place refining fixtures, your furnaces, saws, 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!

Angled view of the ocean zone showing the beach, cliffs, and coastline with red blocked tiles painted over decorative rocks and cliff edges
The ocean zone from a perspective angle. You can see how the red tiles hug the cliff edges and decorative rocks.

Anyway, making the grid system so much larger, and making sure it was still compatible with people's old save files, there was a lot of coding involved, and careful adjustments. 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. I tried a few different methods initially, but the new tool was what I ended up making for it. I'll be sharing all of that and a bunch of other stuff too.

In-game screenshot of the player standing on the grassy edge of the farm next to purple flowers and a wooden log, with the red barn and a cabin in the background and water visible at the bottom of the screen
Standing out at the river edge where the farm meets the water.
In-game screenshot of the player fishing in the new water area with tall grass reeds along the bank, a Set the Hook prompt floating above the fishing line
Fishing down in the new water area. Something you couldn't do before.

The artist also sent over the final version of the new farm zone background recently and it's pretty sweet. It has more personality, like dog faces built into the mountain rocks and other details. We ended up making it kind of a layered thing. Getting it working properly with different camera perspectives was a little bit challenging, but it works!

The new farm zone background artwork on its own, showing the sun rising over distant blue mountains, green rolling hills with brown cliff faces shaped like animal silhouettes, and a dense pine forest layered in the foreground
The new background on its own. You can kind of see little dog and face shapes in the cliff rocks.

I also set up a bunch of warp zones to enter and exit the new terrain to different areas. Like going from the bottom cave up to the top cave, or from the farm to the beach, town, junction areas, that kind of thing (sparkly indicators included). I also improved the transition from the waterfall into the water visually, which is a relief because it was a bit rough looking before. I also had to rebuild the animal companion pathfinding setup so your cows, chickens, horses, etc, can actually follow you down into the new zone instead of getting stuck at the old farm edge and glitching out - continuously teleporting to you, lol. There's a bunch of other changes and additions too but it's hard to remember them all.

Jump to section

The New Background#

So like I mentioned at the top, 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, not much going on. This new one has a bunch of hand-painted layers stacked at different depths instead. You've got distant snow-capped mountains way in the back, then green mountains with cliff faces in front of those, then a treeline of oaks, and then a dense pine forest up in the foreground. Everything is pixel art and hand-painted by him.

Composite example showing all the hand-painted background layers stacked together, with distant snow-capped mountains, green hills with cliff faces, oak treeline, and dense pine forest in the foreground
All the layers composited together. He sent this as a preview of how they stack.

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, and then each layer gets a bit darker and more detailed as you come forward. The pine trees in the front are individual sprites so I can just scatter them around however I want, which is nice for making each spot on the farm feel a bit different. He also painted left and right halves of a looping pine strip so it tiles seamlessly across the whole width of the zone.

Here's what each of the layers looks like on its own, going from the back of the scene to the front:

The farthest background layer on its own, pale mint-colored silhouettes of snow-capped mountain peaks with no detail in the faces, meant to read as very distant
Distant mountains at the very back. Pale mint so they read as far away.
Mid-distance layer on its own, a rolling green hillside with a single tall green mountain peak on the left and brown cliff faces cut into the hills on the right
Green mountains in front of those, with the first cliff faces cut in.
Closer cliff layer on its own, a detailed brown rocky cliff wall with a grassy top that has little yellow and white flowers scattered along the edge
Closer cliff, left half. Way more detail than the mountains behind it.
Right-side cliff half on its own, a mirrored brown rocky cliff wall with a grassy top, matching the left half so the two tile together across the scene
Matching right half. The two piece together across the width of the zone.
A small grass-topped cliff chunk on its own, a single close-up piece of brown cliff with grass and little flowers on the top edge, painted as a foreground accent piece
Smaller grass-topped cliff chunk. Drops in as a closer foreground accent.
Oak treeline layer on its own, a long row of bushy green oak tree canopies painted as silhouetted foliage clumps with no trunks visible
Oak treeline, sitting between the cliffs and the pines.
Front pine forest layer on its own, a dense row of dark green pine tree silhouettes packed together, designed to loop seamlessly across the width of the zone
Pine forest at the front. Loopable left half.
Right half of the looping pine forest strip on its own, matching the left half so they tile seamlessly across the full width of the zone
Matching right half. The two tile seamlessly across the whole width.
A small cluster of individual pine tree sprites of varying sizes, painted separately from the looping forest strip so they can be scattered around the scene one by one
Individual pine sprites I can scatter on top of the loop.
A small set of four individual pine sprites in different shapes, some fuller, some thinner, painted as separate pieces for scattering into the foreground
Mixed pine sprites, different shapes and sizes.
A set of three tall thin bare pine trunks painted in dark brown with no needles, the skeletal variant sprites used to break up the denser pines
Bare trunks. Breaks up the denser pines so spots don't look uniform.
A single tall thin pine tree sprite on its own, with a visible brown trunk and darker green needles, the kind of piece that gets placed individually in the foreground
And one of the single pines on its own. Shown here at close to its real pixel size.
Another in-game screenshot showing the layered background from a different position on the farm, with the pine forest and mountain layers visible behind buildings and terrain
Same thing from a different spot on the farm. The layers shift as the camera moves.

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 like I mentioned earlier 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.

Scene view of the waterfall in Cornucopia showing improved blending where the waterfall meets the river water at the top of the cliff
The waterfall blending into the river at the top. Used to be a hard edge there.

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. (Or actually any area in the game too that makes sense.) Furnaces, saws, sprinklers, scarecrows, tumblers, that kind of stuff. 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)

So with the new ocean zone connecting to the farm, I wanted the same thing to be true down there too. Like all the 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 people in early access either, since they already have their whole farm laid out on the old terrain shape, and all their saved soil values and vegetable plant positions... So I had to kind of redo the whole thing from scratch to handle the changes as well as old save compatability. (btw, doing development with having to worry about saving/loading compatability and translations makes everything harder, so I recommend new dev's 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 setup. I can paint from the top down view for covering big areas fast, or switch to the in-game perspective view for the fiddly spots where I need to nudge tiles around individual decorative props. I end up switching back and forth between the two views a lot.

Top-down scene view of the farm terrain with red blocked tiles painted across decorative areas, progress indicator showing 85 percent complete
Further along. That "85%" up top is the counter telling me how much of the map I've painted.

The tool itself is done now, and I've also already finished hand-painting all the blocked spots across the whole new terrain too, which was honestly something I procrastinated a bit on... Some of these screenshots are from while I was still in the middle of it.

On a different topic; Another other thing I had to fix was the actual blue grid line visual itself due to the new varied terrain. When you're playing and looking to place a refining fixture in placement mode, the game draws these blue grid lines on the ground so you can see which tiles and available and which are occupied (in red). Technically the way it works is it projects a decal downward from above the camera, and the shader reads the depth buffer to figure out where the ground is and draws the lines onto it. On the old mostly flat terrain that worked fine. But on the new terrain with all the cliffs and waterfalls and elevation changes, the grid was drawing on everything including some cliff faces too. Not exactly professional to keep it like that.

In-game screenshot showing blue placement grid lines incorrectly rendering on a waterfall and vertical cliff faces instead of only on flat walkable ground
Grid lines showing up on the waterfall and cliff faces. Not great.
In-game screenshot showing red blocked tiles and blue placement grid lines incorrectly drawing onto a vertical waterfall and cliff face behind the player's saw fixture
Same problem showing up on the waterfall too. Grid and blocked tiles both crawling up the cliff face.

So the fix was basically a few things. The original version of the 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, and I also shrunk the height of the projector box so it doesn't reach as far down vertically, which means it catches less cliff face in the first place. There's also a smooth fade near the cutoff angle now so the grid doesn't just hard-clip at the edge, it kind of fades out gradually, which looks way more natural on slopes.

In-game screenshot of placement mode working correctly after the fix, with blue grid lines sitting flat on walkable ground and cliff faces kept clean, with red blocked tiles only around decorative flowers
After the fix. Grid sits flat on the walkable spots, and the cliff face stays clean.

How To Make A Grid Blocker Tool (For Other Unity Devs)

If you want to build something similar, here's how I wired this one up. Skip past this part if you're not into Unity editor stuff.

The Component

The blocker is a MonoBehaviour that sits on the Terrain GameObject. The data it saves is just two int arrays called blockedTilesX and blockedTilesZ. Entry i in both arrays together makes up one blocked tile. I went with two flat int arrays instead of a list of Vector2Int mostly because Unity's default serialization handles int arrays fine without me having to write any custom save code for it.

When the game starts up, ApplyToGrid() walks through the arrays and for each pair it converts the world coordinate into a grid index, then flips the matching entry in a second boolean map called gridMapSimplifiedCantPlaceHere to true. The placement system already had a gridMapSimplified layer that tracked whether something was currently sitting on a tile, so adding a second "is this tile allowed at all" layer was basically one extra line in the placement check:

if (!groundGridReference.gridMapSimplified[x, z] &&
    !groundGridReference.gridMapSimplifiedCantPlaceHere[x, z])
{
    // Placement allowed.
}

So now placement just checks both maps instead of one. Old map says "is something already here," new map says "is this tile even allowed." If either one trips, nothing gets placed.

The Editor Tool

The editor side is a custom Unity Editor inspector on the component, plus a scene view handler that takes over your mouse while paint mode is on. It works in both the top-down orthographic view and the regular perspective scene view. Basically the same thing happens in either one. It shoots a ray from the mouse cursor down onto the ground, grabs whichever tile is under the cursor, and paints that. I use top-down most of the time when I'm painting over a big open area. For the fiddlier spots, like tiles tucked under a rock I can't really see from straight above, I'll flip to perspective and tilt the camera around like I'm the player. There's a T key shortcut that snaps you into top-down view whenever you want it.

There's a few different paint modes, and they all work the same in either view.

The main one is just a brush. Ctrl plus left click paints whichever tile you're hovering, or a square of tiles if brush size is bigger than 1. Ctrl plus right click erases. Brush size only goes up in odd numbers, 1 through 15, so the brush always centers cleanly on the tile your cursor's on. A HashSet keeps track of whatever tiles got touched during the current session, so painting over the same area twice doesn't add duplicate entries.

There's also a box fill mode for bigger areas. Ctrl plus shift plus drag draws a rectangle across the ground. While you're dragging, there's an overlay in the scene view that shows the live width, height, and total tile count of the box you're drawing. I added that because without the feedback I kept accidentally painting 40 by 40 squares and wondering why half the map had gone red.

And then there's a local undo on the Z key that pops the last action off a 30 step stack. I kept hitting Ctrl Z out of muscle memory and triggering Unity's own undo system, which would undo half my paint stroke and then some unrelated gameobject move from ten minutes ago, so I ended up moving the local undo onto its own key.

Performance

Not really something I had to worry about here. It's one boolean lookup per placement attempt, and that only happens when the player clicks to put something down. So there wasn't much to optimize on this one.


Warp Zones#

Okay so like I also mentioned up top, I 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, all that kind of stuff. Makes the whole map feel way more connected instead of just one flat expanse of disconnected zones. Sparkly indicators included so you know where they are.

Scene view of a zone warp trigger in Unity, with a glowing particle effect marking the entry point between two zones
A warp trigger with its little glow effect on it so I can see where it sits in the scene.

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 or whatever. 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.

Scene view showing Rufus the farmer sprite placed at a spawn point near the farm junction to mark where the player should arrive after warping in
Farm junction landing spot.
Scene view of Rufus the farmer sprite placed inside a cave as a reference for the player's spawn position after warping into the cave
Inside the cave. Where the player comes out.
Scene view of Rufus placed next to a campfire in a zone to mark the player's warp landing position by the fire
Next to the campfire, another spawn point.
In-game view of the player character standing on the beach after warping down from the farm, with ocean and cliffs in the background
In-game view after warping down to the beach. Everything lines up.

Farm Animal Pathfinding#

One more thing I wanted to mention was the farm animal pathfinding stuff. So all your farm animals, like your cows, your chickens, your horses, whatever you've got following you around, they use A star pathfinding to keep up with you. Which is basically a grid layer that sits underneath the whole terrain and says what spots are walkable and what spots aren't, and then 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 and definitely not what I wanted.

Scene view showing the A star pathfinding graph rendered as a mesh of blue walkable nodes over the terrain, covering the farm, junction, and ocean zones
The new pathfinding graph. All that blue mesh is every spot an animal is allowed to walk.

So I rescanned the pathfinding graph across the whole new terrain. Like 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.

In-game screenshot of the player standing in a grassy meadow full of dandelions and rocks, with a cow following the player around the farm
Cow following me around the farm.

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

In-game underwater screenshot of the player fighting a purple squid enemy with a pickaxe amidst seaweed on the ocean floor, a speech bubble reading I am running out of breath above the player
Fighting a squid on the ocean floor. Breath meter ticking down.

Comments