Need Help with my Transportation System

hi, i wanna make a boat transport system

i have what it needs to move, but its really funky. the video explains it all


(if the video doesn’t load, i uploaded them to my cdn server,
the funny one
the serious one
the funny one is funny because helicopter.)

i want the orientation for the full model to follow its target path part, but its just not doing that :confused:
if anyone is big megabrain and can solve this for me, I’ll make sure to compensate you for it.

if you want to solve this with all assets (its going to be easier, trust me)
the problemo.rbxl (133.6 KB)
if you dont, heres the code for the boat.

--[[
			a pretty crudely made boat transportation script........ 
                              made by supex
				     	please fix this if you can
]]

local model = script.Parent
local primaryPart = model:FindFirstChild("riverboat15")
local driveBool = model:FindFirstChild("Drive")
local engineSound = model.riverboat27:FindFirstChild("goblinriverboat_engine_drive_01")
local TweenService = game:GetService("TweenService")

local verticalAmplitude = 0.61
local horizontalAmplitude = 0.26
local tiltAmplitude = 2.567

local pathFolder = game.Workspace.Paths[model.Name]
local pathPoints = pathFolder:GetChildren()
local currentPointIndex = 1
local speed = 0.75
local originalPosition = primaryPart.Position
local originalOrientation = primaryPart.Orientation
local t = 0

while true do
	local waterWaveSize = workspace.Terrain.WaterWaveSize
	local waterWaveSpeed = workspace.Terrain.WaterWaveSpeed
	local newY = originalPosition.Y + math.sin(t * waterWaveSpeed) * verticalAmplitude * waterWaveSize
	local newX = originalPosition.X + math.cos(t * waterWaveSpeed) * horizontalAmplitude * waterWaveSize
	local newTilt = originalOrientation + Vector3.new(0, 0, math.sin(t * waterWaveSpeed) * tiltAmplitude)

	local newZ = originalPosition.Z
	if driveBool.Value then
		if (primaryPart.Position - pathPoints[currentPointIndex].Position).Magnitude < 10 then
			currentPointIndex = currentPointIndex % #pathPoints + 1
		end
		local direction = (pathPoints[currentPointIndex].Position - primaryPart.Position).Unit
		newX = originalPosition.X + direction.X * speed
		newY = originalPosition.Y + direction.Y * speed
		newZ = originalPosition.Z + direction.Z * speed
		local lookAtCF = CFrame.lookAt(primaryPart.Position, pathPoints[currentPointIndex].Position)
		local _, targetY, _ = lookAtCF:ToOrientation()
		targetY = math.max(-100000, math.min(100000, math.deg(targetY)))
		local targetOrientation = Vector3.new(primaryPart.Orientation.X, targetY, primaryPart.Orientation.Z)
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		local tween = TweenService:Create(primaryPart, tweenInfo, {Orientation = targetOrientation})
		tween:Play()

		if not engineSound.IsPlaying then
			engineSound:Play()
		end
	else
		if engineSound.IsPlaying then
			engineSound:Stop()
		end
	end

	model:SetPrimaryPartCFrame(CFrame.new(newX, newY, newZ) * CFrame.Angles(math.rad(newTilt.X), math.rad(newTilt.Y), math.rad(newTilt.Z)))
	originalPosition = primaryPart.Position
	t = t + 0.01
	wait()
end

help is very much appreciated :sunglasses::+1:
-supex

The issue is caused by tweening orientation which disconnects the boat.

I suggest using a CFrame value instead (in order to be tweenable without effecting the actual parts CFrame) and adding an extra orientation CFrame value in the model moving line, this should keep the tilting while also allowing orientation of the whole model in a certain direction:

local positionCFrame = CFrame.new(newX, newY, newZ) 
local orientationCFrame = cframeValue.Value
local tiltCFrame = CFrame.Angles(math.rad(newTilt.X), math.rad(newTilt.Y), math.rad(newTilt.Z))
model:PivotTo(positionCFrame * orientationCFrame  * tiltCFrame )
1 Like

wow, thank you so much!!!
that really helped out :smiley:

do you want compensation? let me know in personal messages :+1:

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