NOTE: This project is kind of old and the example place is broken. However, you can still fix and use the source code. I might make a new version of this in the future where I address the texture movement and stretching issues.
From my uncopylocked place: ‘Sea (Open Source) - Roblox’.
Motivation
I decided to give the infinite sea another try. There is an earlier post that I made that features a sea with custom physics. People seemed to be the most excited about the sea, which is the main reason why I started this little project.
Tools
This project is written in plain Luau (not typed/strict). The tools that I used are Rojo, Git and Quenty’s NevermoreEngine. A GitHub repository for this project is made and can be found here. You can also copy the project’s contents from the example place.
How it works
The sea itself is a skinned mesh. The starting mesh is transformed. Each bone is exponentially displaced by its original distance from the mesh’s origin. This results in a sort of level-of-detail effect, where the bones in the middle are more dense than on the outside.
Before each frame, the mesh is repositioned under your character’s head. Then the bones are updated based on the time and their last position. This process requires a custom mathematical function that is defined as the following in the example:
local AMPLITUDE = 20
local SCALE = 100
-- p is the last position of the bone
-- t is the current time
return function (p, t)
return Vector3.new(
p.X,
AMPLITUDE * math.sin(p.X / SCALE + t) * math.cos(p.Z / SCALE + t),
p.Z
)
end
The time is obtained by using the TimeSyncService module from the Quenty/NevermoreEngine. This should ensure that the waves are synchronized with the server.
Limitations
The texture does not move. This might give the illusion that the player is not moving. Although, reference points like islands can mitigate this problem.
References
- Earlier article about an infinite sea and custom physics: Custom Medium Physics (Open Source)
- TimeSyncService module from NevermoreEngine: NevermoreEngine/src/timesyncservice at main · Quenty/NevermoreEngine · GitHub
- GitHub repository: https://github.com/cassis163/rbx-sea
- Example place: Sea (Open Source) - Roblox