How To Code a Swimming Fish In a Tank

Last updated: February 10, 2025

  1. Start with your fish in the tank. If it's made up of multiple parts, make sure to hit Merge with the Group Parts tool.
It needs to be merged or you won't be able to open the code builder.

  1. Open the code builder for the fish and name it. From the Events section, place a At Start block, followed by a Do Forever block from Control.

  2. Inside, place a make object look at --- and then a tween object position to --- from the Motion Section. In the object name, name both "SwimTo".

  3. Follow up with a wait -- seconds block from control and change the seconds if you'd like.

  4. Repeat these 3 blocks, however, change the name to "SwimBack" on the other 2 motion blocks.

  5. Place one block at either end of the tank walls.

  6. Select one of them and name it "SwimTo" using the code builder. Do the same for the other block, naming it "SwimBack".

  7. Rotate both blocks 180 degrees so that they are facing away from each other.

  8. Select both blocks and change the Transparency to "1" with the Material tool to hide the blocks.

  9. Press play to watch your fishy swim back and forth in its tank!

Was this article helpful?

Thanks for your feedback!