September 20 - How Fishing Works

Hello again! There are A LOT of fixes, tweaks, and new survival gameplay in this week. Far too many to cover, so check out the patch notes. I'll do a quick summary: sprains, painkillers, lettuce plant, ice cream, lakes, console commands, wind, clothes, snow, weather, and like a page's worth of bug fixes.

Instead, let's talk fishing, and how it was implemented. Fishing was one of the most complicated tool interactions so far and I ended up breaking it up into 3 components. The rod itself, the fishing bobber, and the fishing line.

I wanted to avoid adding a bunch of new variables to handle fishing since multiple players could fish on the same server at the same time, so I decided to piggyback onto my buffs and debuffs system. When you first use your fishing rod you gain the "cast line" debuff which counts up how long you have the button held down. Once released, it fires a line straight forward from your character based on their facing out to a certain distance based on the range of the rod and how long you held the button down. It then shoots another raycast straight down to find the terrain and checks if the point it hits is a water block. If it is, the debuff expires and you gain the fishing debuff. Why debuffs? Because you can remove buffs by right clicking, and I didn't want you to accidentally remove these.

We then add the fishing bobber to the point the raycast hit, which sits there and floats up and down occasionaly. It's linked to the player so it knows it's yours, and will be automatically cleaned up if anything makes you stop fishing.

I added a new behavior to fish that will check for nearby fishing bobbers and go investigate. A nibbling fish causes the bobber to bounce up and down.

While fishing you can press the button to pop the bobber back to the surface and reel it in, which causes it to move towards the player and check for valid water spots as it does. If it ever can't find one, you've reeled it in completely. When the bobber is bouncing from a nibbling fish, if you reel it in while it's below the surface of the water, that's a bite and you move to the "reeling it in" debuff.

The final component is the fishing line, attached from the rod to the bobber. This uses a simple line render with 3 basic points: The rod, the bobber, and the halfway point. I added a bezier curve script to smooth out the line render and create a nice curve from the rod to the bobber by dropping the halfway point down a bit. To simulate tension on the line while reeling, I turn off the curve when you're reeling in the bobber and add a lerp to Y position of the halfway point to smooth out the movement of the line so it looks like it's actually swaying about.

So you hooked the fish and need to reel it in, at this point it's relatively simple. I mark the fish as hooked and have it move with the bobber. It also tries to run away, so if you let up on the line it'll bolt and take the bobber with it. If it gets too far away, it gets away so it's a battle of stamina management. I wanted to use the actual fish NPC the whole time with minimal modifications instead of swapping it out for a fishing model, because part of the gameplay is about how everything interacts with each other. So while it's on your line that fish is still interactable. Someone else could come up and spear it to steal it from you, or maybe a bigger fish will want a snack. Anyway, once it's reeled in you've got the fish! I added a little model viewer thing so you can look at your catch, and its length is recorded in your journal.

Now you know how fishing is done. It's one of those things that seems relatively simple and straight-forward but becomes a lot more complicated once it needs to be implemented for a game. See you next week!

Continue Reading in the Dev Forums >>

<< Return to Devlogs