UNREAL ENGINE 4
RIGGING AND ANIMATION
Since I couldn't find any free 3D rigged and animated turtle models, I took an existing free turtle mesh, where the whole body was one contiguous mesh, and imported it into Maya, where I rigged and animated it in order to achieve the kind of calm swimming motion I was aiming for.
The turtle's forward movement is always determined by the mesh's forward vector. The Current Swim Speed is constantly being reduced by the Swim Drag, which simulates the turtle slowing down between each swim stroke.
If the swimming animation has finished playing, and the swim button is being held down, the animation plays and Current Swim speed is set to 1,5, accelerating the turtle using the script above.
TURNING AWAY FROM WALLS
By linetracing both straight up and down from the head of the character, as well as forwards from its shoulders, the controller makes sure that the turtle can sense when a floor, wall or the surface of the water is approaching.
If a floor or the water's surface is within a set minimum distance, the controller set the pitch of the character seen under "Swimming" to a Correction Angle of either 25 or negative 25 degrees, depending on whether the turtle is approaching a floor or the surface, and then keeps that correction angle until it's outside that minimum distance.
The roll and pitch of the character is slowly lerped towards its maximum values, based on the input from the gamepad thumbstick.
Camera pitch and yaw are stored as variables, clamped between max and min values.
The pitch of the camera is constantly being lerped towards an angle which is 25 degrees down from the character's pitch, meaning it has a slight top-down perspective.
By pressing down on the right joystick button, the game helps the player reset the camera to position behind the turtle again.
If the player is approaching a wall, the distances of the two forward facing linetraces determine which shoulder of the turtle is closest to the wall, and turns the turtle in the direction of the shoulder that is the furthest away.
A character controller prototype, exploring underwater motion and traversal.