This morning I’ve decided to see if I could simulate mechanical waves in Roblox. What I found is that one can create these waves really rather easily by harnessing the power of physics.
I went about creating these waves by using a generalized wave equation which gives vertical displacement as a function of x-axis position and time. (Code pictured below)
Where:
t = time
y = y-axis position
x = x-axis position
WL = wavelength
PRD = period
k = spatial frequency
omega = angular frequency
A = amplitude
- Simple waveforms
By using a generalized wave equation, we can simulate simple and highly customizable sinusoidal waveforms. The waveform can easily be tweaked by adjusting variables like wavelength, period, and amplitude. (Note that although it looks like the cubes are moving to the left, they are actually simply oscillating upward and downward)
- Waveform customization by Fourier analysis
By using Fourier series, we can achieve even higher levels of waveform customization. Pictured below is an approximation of a square wave using a simple Fourier Series (Again, the cubes are only oscillating upward and downward, they are NOT moving to the left)
- Applications
Probably the most immediate application is a simple method to create periodic animations for objects in a game. I think the principle can be expanded further to create more fascinating in-game applications, but if not, at least it looks cool.