Rotate boat to align with hulls (custom water)

i got a boat that has hulls and each one is moved to the position i want them to be. i want to rotate the boat (with a body gyro) to align with all of those points
for example, if the front hulls are further down, the boat should tilt down

right now i have something but it doesnt do what i want

picture of the boat not tilting down

this is the code

local averagePosition = Vector3.zero

for i, hull in pairs(self.hulls) do
    -- hullpart is the part its trying to align to
	local currentPos = hull.hull.Position
	local newPosition = Vector3.new(currentPos.x, self.waterLevel, currentPos.z)
	
	hull.mover.Position = newPosition
	averagePosition += hull.hullPart.Position
end
averagePosition /= self.hullCount
averagePosition += self.boatOffset

-- rotation code below
local direction = (averagePosition - self.moverAlign.Position).Unit
if direction.Magnitude ~= direction.Magnitude then -- NAN (not a number) checks
	direction = Vector3.new(0, 0, 1)
end
self.rotAlign.CFrame = CFrame.lookAt(self.moverAlign.Position, direction)
-- rotation code above

self.moverAlign.Position = averagePosition

solved the issue by figuring out the average position in the front, back, left, and right then calculating the front and sideways angles then combining them together into one cframe

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