We’ve been working on this project for a while now, we are trying to create the ability for ships to float on our custom made water (made using mesh deformation).
We’ve gotten this far, but have now ran into some slight issues.
As you can see, we have the correct motion, however the ship seems to gain momentum and has overshot the water.
Here is the code i’m currently using:
script.Parent.BodyGyro.CFrame = script.Parent.CFrame
local Controller = require(game.CollectionService:GetTagged(“2A9746FA-AD27-46FA-B54C-4468D23213B2”)[1])
–local Controller = workspace:WaitForChild(“Workspace”):WaitForChild(“Ocean”):WaitForChild(“Controller”)
local displacement = Controller.GetDisplacementAtPosition
local RunService = game:GetService("RunService")
local part = script.Parent
local Bow = workspace.Ship.Boat.Hull.Bow
local stern = workspace.Ship.Boat.Hull.Stern
local left = workspace.Ship.Boat.Hull.Left
local right = workspace.Ship.Boat.Hull.Right
local graity = workspace.Gravity
local UpVector = Vector3.new(0, 1, 0)
RunService.Heartbeat:Connect(function()
local Tile = Controller.Object.Parent.Tiles:FindFirstChildOfClass("MeshPart")
local GlobalMoveCFrame = CFrame.lookAt(Vector3.new(),
workspace.CurrentCamera.CFrame.LookVector - workspace.CurrentCamera.CFrame.LookVector:Dot(UpVector) * UpVector, UpVector)
local GlobalMoveVector = GlobalMoveCFrame:VectorToWorldSpace(Vector3.new(0, 1, 0))
local DisplacementBow = displacement(Bow.Position, GlobalMoveVector, Bow:GetAttribute("Displacement"))
local DisplacementStern = displacement(stern.Position, GlobalMoveVector, stern:GetAttribute("Displacement"))
local DisplacementLeft = displacement(left.Position, GlobalMoveVector, left:GetAttribute("Displacement"))
local DisplacementRight = displacement(right.Position, GlobalMoveVector, right:GetAttribute("Displacement"))
local SampleFront = script.Parent.Bow.Position * Vector3.new(1,0,1) + Vector3.new(DisplacementBow.X, Tile.Position.Y + DisplacementBow.Y, DisplacementBow.Z)
Bow.BodyPosition.Position = SampleFront
local SampleBack = script.Parent.Stern.Position * Vector3.new(1,0,1) + Vector3.new(DisplacementStern.X, Tile.Position.Y + DisplacementStern.Y, DisplacementStern.Z)
stern.BodyPosition.Position = SampleBack
local SampleLeft = script.Parent.Left.Position * Vector3.new(1,0,1) + Vector3.new(DisplacementLeft.X, Tile.Position.Y + DisplacementLeft.Y, DisplacementLeft.Z)
left.BodyPosition.Position = SampleLeft
local SampleRight = script.Parent.Right.Position * Vector3.new(1,0,1) + Vector3.new(DisplacementRight.X, Tile.Position.Y + DisplacementRight.Y, DisplacementRight.Z)
right.BodyPosition.Position = SampleRight
local CustomLookVector = SampleFront - SampleBack
local CustomRightVector = SampleLeft - SampleRight
local Rotation = CustomLookVector * CustomRightVector
--script.Parent.BodyGyro.CFrame = CFrame.fromMatrix(CustomLookVector,CustomRightVector,CustomLookVector)
--script.Parent.BodyGyro.CFrame = CFrame.fromMatrix(CustomLookVector,Rotation,CustomRightVector)
end)
-- Gyro
If you know what’s wrong here please leave suggestions and answers! Thanks!