How I Made Fish Swim

How I Made Fish Swim

Zeemeermin πŸ“… 03 October 2025 πŸ‘ 1451 views

In the intro of my app, about 40 fish swim from right to left. When you tap or swipe across the screen, they react: they speed up and the entire school changes rhythm. The fun part? I didn’t animate their movement with keyframes, but literally drew it with my finger on the screen.

From Finger Movement to Fish Paths

While prototyping, I wanted the animation to feel human and playful. So I built a system that recorded my finger movement and turned it into paths:

  • I swiped my finger across the screen; the app stored the x and y coordinates per frame.
  • These coordinates were converted into a route (polyline/spline) for the fish.
  • Each time the app started, the fish followed these paths β€” as if they were chasing my hand.

Interaction: Swimming Faster on Touch

The fish react to touch events. If you tap a fish (or the water), the app temporarily increases their speed and sometimes changes the density of the school. This made the intro feel lively and responsive.

Technical Details (Objective-C)

The snippet below shows how I recorded touch points and generated a path that each fish could follow. (Simplified for readability.)

// Touch recording (UIView / Scene overlay)
@property (nonatomic, strong) NSMutableArray<NSValue *> *touchPoints;

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UITouch *t = [touches anyObject];
    CGPoint p = [t locationInView:self.view];
    if (!self.touchPoints) self.touchPoints = [NSMutableArray array];
    [self.touchPoints addObject:[NSValue valueWithCGPoint:p]];
}

// Generate path (simplified) and assign to fish
- (UIBezierPath *)pathFromTouchPoints {
    UIBezierPath *path = [UIBezierPath bezierPath];
    if (self.touchPoints.count == 0) return path;
    CGPoint start = [self.touchPoints.firstObject CGPointValue];
    [path moveToPoint:start];
    for (NSValue *v in self.touchPoints) {
        [path addLineToPoint:[v CGPointValue]];
    }
    return path;
}

// Each fish gets an offset on the same base path for variation
- (void)assignPathToFish:(FishSprite *)fish basePath:(UIBezierPath *)path offset:(CGFloat)offset {
    // offset translates the path slightly in y-direction or via timing shifts
    fish.motionPath = [path copy];
    fish.pathOffset = offset;
}
  

Why This Works for the Experience

  • Natural rhythm: hand-drawn paths have micro-variations that feel β€œalive.”
  • Immediate feedback: touch = speed up. Kids and adults understood it instantly.
  • Tech supports emotion: code makes the magic possible, but the experience is what matters.

The Lesson I Took Away

Not every animation needs to come from a tool or keyframe editor. Sometimes a tactile approach β€” recording movement with your finger β€” gives exactly that organic feel that’s hard to simulate with pure code. Combining touch recording, path generation, and real-time interaction turned a simple intro into a playful, magical moment.

Gallery

← Back to Blog