Link to my project
Brief Description:
In this project, I made a group of fish freely swimming in a pool. When you click on the water, the ripples will appear.
Visual Documentation:
Coding:
Inspired by Leon, I tried to use noise() to control the movement of the fish. First, I tried to use noise() to change the speed but I found the object moved in one direction and went out of the canvas. So, I used noise() to directly change the x and y positions and make the fish move.
To rotate the fish to face the direction it is moving, I store their position in an array every frame and use them to calculate the angle. I also splice the element out to control the length of the array.
I translated two times to make the shadow and the shadow was rotated to the same angle as the fish.
Reflection:
Beyond lerp(), noise() can also produce movement like animals. To go further, I want to let the fish swim away from the ripple, but I haven’t figured it out.