What do you want to achieve? Keep it simple and clear!
I want to create a mount system using tweening.
What is the issue? Include screenshots / videos if possible!
When rotating, the tween doesn’t take the shortest path, and it doesn’t stop rotating when you stop, until it has reached its goal. (fixed crossed out issue) https://streamable.com/5dhkxz
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to pause the tween, but that does not seem to work.
Here is my code:
local Seat = script.Parent
local TS = game:GetService("TweenService")
local mbp = script.Parent.Parent.MountBasePart
local moving = false
spawn(function()
while true do
wait()
local ti2 = TweenInfo.new(
.1
)
local t2
if moving == true then
local moveto = mbp.Position + mbp.CFrame.LookVector
print(moveto)
t2 = TS:Create(mbp, ti2, {Position = moveto})
t2:Play()
else
end
end
end)
local prevtween
spawn(function()
while true do
wait()
if Seat.Occupant then
local wd = Vector3.new(Seat.Occupant.MoveDirection.X, 0, Seat.Occupant.MoveDirection.Z)
local sp = mbp.Position
local wto = sp + wd
local mag = (sp - wto).Magnitude
local ti = TweenInfo.new(
.5 * mag
)
local x, y, z = CFrame.new(sp, sp + wd):ToOrientation()
local t = TS:Create(mbp, ti, {Orientation = Vector3.new(math.deg(x), math.deg(y), math.deg(z))})
if Seat.Occupant.MoveDirection ~= Vector3.new(0, 0, 0) then
if moving == true then
t:Play()
print("played")
prevtween = t
else
prevtween:Pause()
print("stopped")
end
else
prevtween:Pause()
print("stopped")
end
end
end
end)
local function rotate()
if Seat.Occupant then
if Seat.Occupant.MoveDirection ~= Vector3.new(0, 0, 0) then
moving = true
else
moving = false
end
else
moving = false
end
end
local function onChanged(property)
if property == "Steer" then
rotate()
elseif property == "Throttle" then
rotate()
elseif property == "Occupant" then
rotate()
end
end
script.Parent.Changed:Connect(onChanged)
I don’t think you get what I meant…
The tweening works (almost) perfectly.
The only 2 issues that I’m facing is that the tween doesn’t always take the shortest path to its destination and always finishes what it’s doing instead of pausing when I want it to pause.
I have already tried that, and I do not see any difference in using :Pause() and :Stop()
I think I know how to fix that though, so for the moment my main concern is the tween not taking the shortest path.
Yup. Just as I thought, I fixed one of the issues.
The only issue is that the tween is not taking the shortest path.
I have updated the thread with my current script.