I want to make a ship that will stay on the surface of skinned mesh ocean. I use this function to create waves:
function GerstnerWave(SamplePosition,Wavelength,Direction,Steepness,Gravity,SampleTick)
local k = (2 * math.pi) / Wavelength
local a = Steepness/k
local d = Direction.Unit
local c = math.sqrt(Gravity / k)
local f = k * d:Dot(Vector2.new(SamplePosition.X,SamplePosition.Z)) - c * SampleTick
local cosF = math.cos(f)
local dX = (d.X * (a * cosF))
local dY = a * math.sin(f)
local dZ = ( d.Y * (a * cosF))
return Vector3.new(dX,dY,dZ)
end
-
What is the issue? I can’t get the Y vector of the wave.
-
What solutions have you tried so far? I looked for solutions on Devforum
Here is my buoyancy script:
local Object = workspace:WaitForChild("base")--boat base
local rs = game:GetService("RunService")
local module = require(workspace.Wave2)--wave module
repeat wait() until workspace:WaitForChild("Water"):FindFirstChild("Plane")
Object.Anchored = false
local beforeSubmerge = workspace:WaitForChild("Water"):FindFirstChild("Plane").Position.Y + 1
local DisplacementAmount = 3
local DisplacementMultiplier = math.clamp(Object.Position.Y / beforeSubmerge,0,1) * DisplacementAmount
local waterDrag = 0.5
local waterAngularDrag = 0
game:GetService("RunService").Heartbeat:Connect(function(DeltaTime)
for _,v in pairs(Object:GetChildren()) do
--The part I'm having problems
--I need to get the top position of the wave and store it in TopWater
local Force = v.VectorForce
if TopWater then
if v.Position.Y < TopWater then
Force.Force = Vector3.new(0,(game.Workspace.Gravity * DisplacementMultiplier) * (math.abs(TopWater - v.Position.Y) /Object:GetMass()),0)
else
Force.Force = Vector3.new(0,0,0)
end
end
end
end)
Thanks in advance.