![](https://denysalmaral.com/wp-content/uploads/2024/07/fa_thumbnail_4_820x461px.png)
Welcome to the Fish Alive Unity Package, a collection of low-poly animated reef fish designed to bring vibrant underwater life to your AR/VR, mobile, and desktop games. With natural swimming and customizable behaviors, these fish are ready to dive into your scenes.
What is included?
![](https://denysalmaral.com/wp-content/uploads/2024/07/fishInventory.jpg)
![](https://denysalmaral.com/wp-content/uploads/2024/07/coralReefInventory.jpg)
Fish skinned meshes | 9 |
Animations (per fish) | 7 |
Average triangles (per fish) | ~460 |
Coral Reef static meshes | 21 |
Total script (.cs) files | 9 |
Textures | 3 |
Materials | 3 |
Custom Shaders | 0 |
Demo scenes overview
DemoBenchmark.unity
![](https://denysalmaral.com/wp-content/uploads/2024/07/demoScene.jpg)
Play with DemoBenchmark to see smooth swimming while testing their performance. Use the buttons to multiply the fish to create beautiful crowded schools. Watch out for the FPS (Frames Per Second) on top left and fish “count” above Reset button.
DemoMinimal.unity
![](https://denysalmaral.com/wp-content/uploads/2024/07/demoMinimal.jpg)
Just the essential elements. A fish with FishMotion behavior and a cube target to follow. Start here to test or try anything. Click play and move the cube from Scene view to see the swimming happening.
DemoPrettyCoralReef.unity
![](https://denysalmaral.com/wp-content/uploads/2024/07/demoPretty.jpg)
Full demo, everthing all at once and pretty! This scene also showcase the use of our helper class GroupOfFish and demonstrate how to add effects and interactions.
Quick start
- Drag and Drop: Simply drag the prefab of the fish you want to use into your scene.
- Assign a Target: Select the fish in your scene and assign a target GameObject in the FishMotion component. Click play and the fish will organically swim towards this target.
The scripts
Fish Motion component
![](https://denysalmaral.com/wp-content/uploads/2024/07/fishMotionComponent.jpg)
The FishMotion class is responsible for controlling the fish character. Encapsulates the logic required for simulating realistic and interactive fish behavior, including movement, animations, interactions with targets, and responding to environmental constraints.
Target: The GameObject to follow. The script will “ping” its location every certain amount of time (Defined as Target Ping Frequency in the Swim Config object). This value can be modified at any time or set to none|null and the script will just work with its last rememberd location.
Target Reach Mode:
- Wander: Fish will never try to reach exact target position resulting in a gentle swimming around random positions close to the target.
- Position: Reach the exact position (ignoring rotation) and stop there.
- Transform: Reach the exact position and rotation of the target GameObject.
- Biting: Reach the most appropriate position and orientation to later execute a biting animation on the target position. Once there, biting animation could be invoked.
Config: A reference to an scriptable object (class of SwimConfig) that store presets for various parameters for swimming behavior. Three presets are included and already applied to character prefabs:
- SwimAgile: For quick and nimble movements.
- SwimClumsy: For slower, more relaxed swimming.
- SwimNormal: A balanced swimming pattern.
You can assign these SwimConfig presets to any fish through the FishSwim component, or modify them to create your own unique swimming behaviors.
Draw Debug:
![](https://denysalmaral.com/wp-content/uploads/2024/07/fishMotion_drawdebug.jpg)
Visualizes debug information. Avoidance shows a green wired sphere sensor that turns red when hitting obstacles. Path draws the recent movement path.
Animator: Reference to its corresponding Animator component.
Auto Motion: Set this to false to control motion via your own script. If unchecked, FishMotion won’t ping the target or update movement acceleration, resulting in constant motion or stopping. Disabling Auto Motion allows you to manually set Final Acceleration and call FishMotion methods like StartTurnTowardsDirection(…).
Avoidance Enabled:
![](https://denysalmaral.com/wp-content/uploads/2024/07/avoidance.gif)
Instructs our swimmer to attempt obstacle avoidance. If colliders are detected ahead, it will quickly search for the best escape direction within a cone-shaped area. In some cases, an escape route might not be found, and the fish could pass through obstacles.
I refer to this as “soft avoidance.” A more strict avoidance, where the swimmer avoids obstacles at all costs and ensures none are passed, is not yet implemented. The current method prioritizes visual aesthetics and performance.
Final Acceleration:
Final Acceleration represents the force applied to the aquatic creature for accelerated motion. This force isn’t applied instantly; instead, it interpolates over time from the current acceleration to the set Final Acceleration. Since the acceleration changes over time, the motion could approximately follow a cubic curve, resulting in smoother, more natural movement. NOTE: You should manipulate this value only when Auto Motion is previously set to false.
Group Of Fish component
![](https://denysalmaral.com/wp-content/uploads/2024/07/groupOfFishComponent.jpg)
The GroupOfFish class is a handy script for managing multiple fish at once. Just add the GroupOfFish prefab to your scene and make the swimmers its children. GroupOfFish applies your settings to all its child fish and automatically creates and handles moving targets for them.
But wait, it gets even better! Using the Multiply The Fish array field in the inspector, you can easily spawn sets of any amount by specifying the counts and references.
![](https://denysalmaral.com/wp-content/uploads/2024/07/groupOfFishInspector.jpg)
Avoidance Override: If set, obstacle avoidance will be activated for all fish in the group, overriding the existing value.
Use Existing Targets: If any child fish aready has assigned target it will be respected.
Mutiply The Fish: This array lets you spawn sets of swimmers by adding a reference to a fish GameObject or Prefab. The specified amount will be instantiated, and if School bool is checked the group will follow a shared target.
Soft Limits Size: Soft Limits defines the volume area where the fish are likely to swimm. These are the suggested bounds. Targets will move inside but fish are not restricted.
Use Hard Limits: Activete restrictive bounds (see bellow).
Hard Limits Size: Defines strict boundaries that fish will never pass.
Hard Limits Offset: Allows you to offset the volume of hard limits relative to the group, as these volumes are defined at the group’s center.
Bubble Particles Prefab: Adds bubbles when fish go very fast.
Interactions: Adds biting interaction. Fish will bite anything taged “food” and set to layer 20.
Download
Support and Feedback
This project is evolving, anything could be changed to improve or add more features.
Your feedback is important! If you have any comments, questions, or need assistance, please reach out at denys.almaral@gmail.com.
Just keep swimming!