# aquarium effect for 2d fish

i want simple 2d Ai for my fish ,with little R&D i figure out different type of solution but i dont think that is applied to my case

solution that i found was

1)use of way points(but it my fish will use the same path over and over again  which is not god if you have 100 fish and all use one update function each to follow way points

but here also i can only move my object to same point left to rit

but i want effect like aquarium

Just pick a random target point within the aquarium and use Vector3.MoveTowards with the fish speed to move him towards that point. When he reached it, pick a new target.

For smoother movement, don’t move the actual fish with MoveTowards, but another target and Lerp or MoveTowards the fish to this target.
In summary: Pick end target. Move current target with MoveTowards till it reached end target, then pick a new end target. Lerp/MoveTowards tthe fish position between current position and current target. This is similar to what musranya is saying, but produces more even speeds, so the fish isn’t rushing at the start and get slower later and also produces rounded paths like bezier curves and not just linear segments.

If you wanna go more complex, google swarming and flocking behaviour. You’ll probably also find some unity implementations.

Let me know if you have more questions about implementing this solution.

A possible approach would be to create various sets of waypoints (or paths) and then assign the path to each fish randomly. Also you can introduce params when assigning a path to a fish, p.e. variable Lerp velocity between points, an initial position offset, etc.

Another idea taht needs to be tried in order to now if it makes de trick: set points at the corners of the tank and, for the movement of the fish, make a lerp from its initial position to one of these points randomly. After a few secs, change the target point of the Lerp randomly again, and so one. If it works you should have a bunch of fishes swimming around the tank and never reaching the corners

Well, are just a few ideas, anyway hope you can make it

An alternative strategy to explore involves strategically positioning points at the corners of the tank and employing a linear interpolation (lerp) technique to facilitate the movement of the fish. By gradually transitioning the fish’s position from its starting point to one of these randomly chosen corner points, a smooth and continuous motion can be achieved. After a brief interval, the target point for the lerp is randomly reassigned, maintaining an element of unpredictability. If implemented successfully, this method should result in an engaging visual display of fish gracefully swimming throughout the tank, while skillfully avoiding the corners.

These suggestions offer potential avenues for experimentation. I trust that you will find them valuable in your pursuit of the desired outcome.