Boats on mesh deformation ocean

I am working on a game based around water and boats. I already have a mesh deformation ocean using gerstner waves and I have no idea where to start with the boats.

3 Likes

Your gerstner wave function gives you height for a given point on the ocean at a given time, you can use that as part of a buoyancy model, or just glue your boat to that height.

You could have the boat’s Y-position constantly updated to the closest Gerstner wave point under the boat.

while true do
   local range = 1 --should set this to the size of the model plus a few studs
   local boatYPos

   for i,point in ipairs(wavePoints:GetChildren()) do
      local distance = (boat.PrimaryPart.Position - wavePoint.Position).Magnitude
      if distance < range then
         range = distance
         boatYPos = point.Position.Y
   end

   boat.PrimaryPart.Position = Vector3.new(boat.PrimaryPart.Position.X,boatYPos,boat.PrimaryPart.Position.Z)
   task.wait()
end
3 Likes

I’ve tried it but the boatYPos is always the same, it doesn’t change.

Please post your script so others can see how you are trying to control the boat and if there are issues with your script.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.