During our 2-week prototyping course inUnreal Engine 4, I worked with Johan Hyberg and we made a water buoyancy system.
We were inspired by an area in Half-Life 2 where the player has to use the buoyancy of an object to lift a gate, and we wanted to create a buoyancy system that could be used for this style of puzzle game.
We knew we had to play around with adding force to an object to make it float.
We added a line trace from the object downwards to check for the ocean floor and applied force when it came close enough. The amount of force added depended on how close to the bottom the object was.
This method got the object to float, but the force added to the object was equal even if the object fell into the water at an angle, not causing it to align to the surface in a realistic way.
To achieve a more realistic effect, we made a component that could be attached to the object at certain buoyancy points. We then added force to these points based on how close they came to the ocean floor.
When the system was finished, we made items of different sizes and weights and built four levels to demonstrate how this system could be used in a puzzle game.