I have created the function ‘wave()’ as part of a boat script to generate a changing sine wave value. The function is attached to a Runservice.Stepped:wait() and runs every Stepped. After calculating an appropriate sine value, the function will calculate a position value, then will alter a parts position, to make it go up or down depending on the sine value.
local waveVal = 0
local increment = 0.02
local floatDepth = 2
local waterOffset = Vector3.new(0,2,0)
function wave()
waveVal = waveVal + increment
if waveVal >= (math.pi * 2) then
waveVal = 0
end
local newVal = math.sin(waveVal)
float.Position = Vector3.new(0, 0 + (newVal * floatDepth), 0) + waterOffset
end
I want to do this on the client once the client takes control of the boat, though the client has no access to the last ‘waveVal’ value used to change the ship position, it results in an instant position change once they take control. I am able to find the last waveVal value from creating a reversed equation, and using the position of the boat.
-- Server position equation
local newVal = math.sin(waveVal)
float.Position = Vector3.new(0, 0 + (newVal * floatDepth), 0) + waterOffset
-- Reversed equation to get newVal and waveVal
newVal = ((float.Position.y - waterOffset.y)/floatDepth)
waveVal = math.asin(newVal) --Reverse the sine.. Correct? you would think, but no
The reversed newVal equation works and gives me the correct value, though when I attempt to reverse the sine to get waveVal they are not the same, the original waveVal and reverse waveVal work, until they pass a certain value.
I’m convinced I’m just not inversing the math.asin(newVal) correctly. I have ran out of ideas on how I can fix this, and I really don’t want to have to use remote events on something which could be done with math.