Hi! I am working on a sinking simulation for a big boat, however, I can’t find a way to accurately move the model down. So far, the only solution I have is using a while wait repeat, moving it down slowly, with Model:MoveTo, however, I am unable to do that, as you can’t get a model’s previous position, as far as I know. Would anyone happen to have any ideas?
My (tried) solution:
while wait(0.1) do
boat:MoveTo(boat.Vector3+Vector3.new(0,-1,0)) -- doesn't work, as you can't get a model vector3, as far as im aware.
end
If you want to continue with your linear movement of moving a boat, then :
You need to set the PrimaryPart of the boat, which can be set in the model’s properties. (you basically select a main part inside of the boat).
You move the boat either with MoveTo(position) or SetPrimaryPartCFrame(cFrame). I recommend using SetPrimaryPartCFrame in this situation since the boat will collide with the water with MoveTo()
With SetPrimaryPartCFrame, we do the following code.
Problem here is that a Model does not have a CFrame, but you can get the PrimaryParts CFrame and use that to calculate the new position.
Taking the code from @Cadentopia and using the property from above would make the code look like this:
Adding a Vector3 to a CFrame translates it in absolute space. Multiplying it by another CFrame with no rotation will translate it in local space. (relative to the first CFrame’s orientation)
Consider using TweenService instead of a loop that gradually moves the part down. This will still only work on a single part so just as everyone else is saying you will still have to set a primary part and have the other parts welded to the primary part. But TweenService allows you to set parameters to define how long you want it to take to sink the boat.
Example:
local TweenService = game:GetService("TweenService")
local PrimaryPart = Boat.PrimaryPart -- Your boat
local TweenSettings = TweenInfo.new
(5, -- Number of seconds to sink
Enum.EasingStyle.Quad -- Easing Style
Enum.EasingDirection.Out -- Easing Direction
0 -- This number just defines how many times you want the tween to repeat.
false -- Do you want the tween to reverse? (I assume you don't want the boat to unsink).
0) -- Delay time
local EndGoal = {Position = PrimaryPart.Position - Vector3.new(0, -10, 0)} -- How far you want to sink.
local Sink = TweenService:Create(PrimaryPart, TweenSettings, EndGoal}
Sink:Play()
You can read more on TweenService here. It is extremely useful.