> For the complete documentation index, see [llms.txt](https://sunfish-studios.gitbook.io/main/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sunfish-studios.gitbook.io/main/main-components/bobber-controller.md).

# Bobber Controller

Controls the visual bobber: spawns it with a smooth arc or linear trajectory, animates it to the water surface, handles reeling physics, and retreats it back to the rod. Integrates with animation events via the `IBobberSpawner` interface.

> ✅ **Requires**: A bobber prefab (with optional `Aligner` for rotation) and references to the rod tip and fisher.

***

#### 🔧 Inspector Settings

**Bobber Prefab**

The GameObject to instantiate as the bobber. Can be left empty for invisible fishing logic.

**Rod Tip & Fisher Ref**

* **Rod Tip**: Where the bobber originates (e.g., fishing rod tip bone).
* **Fisher Ref**: Used to align the bobber and calculate reeling direction.

**Bobber Positioning**

* **Spawn Interpolation** (`0–1`)\
  Where along the line (or arc) between rod tip and water the bobber initially appears. `0` = at rod, `1` = at water.
* **Use Arc Trajectory**\
  Enables a parabolic cast path for more natural motion.
* **Arc Height**\
  Peak height of the arc (only when arc trajectory is enabled).

**Animation Settings**

* **Animate to Surface**\
  If disabled, the bobber appears instantly at the water surface.
* **Animation Duration** & **Curve**\
  Controls how long and how smoothly the bobber moves from spawn point to water.

**Retreat Animation Settings**

* **Retreat Duration** & **Curve**\
  How the bobber returns to the rod when fishing ends.
* **Retreat Animation Percentage**\
  How long (as % of retreat time) the bobber tracks the moving rod tip.
* **Retreat Despawn**\
  When (as % of retreat time) to hide the bobber—useful for hiding it before the animation fully ends.
* **Retreat Position Offset**\
  Fine-tune the final retreat position, rotation, and scale (great for matching rod animations).

**Reeling Settings**

* **Base Reeling Speed**\
  How fast the bobber moves toward the player while reeling.
* **Reeling Bob Amount / Speed**\
  Adds subtle up/down motion during reeling for realism.

***

#### 📈 Public Methods & Events

**Events**

* `OnBobberTouchWater` — Fired when the bobber reaches the water surface.
* `OnBobberExitWater` — Fired when retreating begins.
* `OnReelerComplete` — Fired when reeling finishes (either by distance or proximity).

**Key Methods**

* `InformWaterHit(Vector3 point, LayerMask waterLayer)`\
  Called by `FishingCaster` to tell the bobber where the water surface is.
* `StartReeling(float speed, float distance)`\
  Begins reeling the bobber toward the player. Called externally (e.g., by a reeling minigame).
* `StopReeling()`\
  Immediately halts reeling motion.
* `HandleFishingEnd()`\
  Cleans up state, hides the bobber, and resets tracking. Called when fishing is canceled or completed.

> 💡 The component automatically responds to `IBobberSpawner` events (`OnBobberSpawn`, `OnBobberRetreat`)—usually triggered by animation events in your fishing state machine.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sunfish-studios.gitbook.io/main/main-components/bobber-controller.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
