Hey, and thanks for reading in advance.
A friend of mine requested that I ‘animate’ the railcar/tram for a space station he’s building. Fortunately, I got it moving back and forth with clean acceleration/deceleration using the TweenService. Unfortunately, doing so does not impart physics to people standing in the tram, so if you’re not sitting down, the tram moves without you and you phase through the walls.
Ultimately it’s a minor inconvenience and/or nitpick, but I was wondering if there was a solution to this that didn’t involve messing around with the incredibly finicky messes that are bodymovers, which were my initial go-to in moving the car, but lacked fine-tuned capability in that I had to calculate exactly where and when to slow them down. The dithering on BodyPositions seemed like an easy fit, but the ReachedTarget event never seems to fire - ever.
Any help or advice is appreciated!
Edit: Here’s the code, if it helps:
local TS = game:GetService("TweenService")
local Tram = script.Parent
local Mover = Tram.Mover
-- SETTINGS
local TRAVEL_DISTANCE = 520
local TRAVEL_TIME = 10
local DEPART_INTERVAL = 5
local DOORSLIDE_TIME = 1
local DOOR_DETECTRANGE = 15
-- DON'T TOUCH
local SlideInfo = TweenInfo.new(TRAVEL_TIME, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local DoorInfo = TweenInfo.new(DOORSLIDE_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local LastTrip = tick()
local TramRunning = false
local Direction = 1
--
local function ToggleDoors(bool)
local OpenDir = 1
if not bool then
OpenDir = -1
end
for _,door in pairs(Tram.AutoDoors:GetChildren()) do
for _,frame in pairs(door:GetChildren()) do
for _,part in pairs(frame:GetChildren()) do
local Goal = part.PartWeld.C0 * CFrame.new(5 * OpenDir, 0, 0)
TS:Create(part.PartWeld, DoorInfo, {C0 = Goal}):Play()
end
OpenDir *= -1
end
end
wait(DOORSLIDE_TIME)
end
--
ToggleDoors(true)
while Tram.Parent and wait() do
if tick() - LastTrip >= DEPART_INTERVAL and not TramRunning then
local Goal = Mover.CFrame + Mover.CFrame.LookVector * (TRAVEL_DISTANCE * Direction)
local Slide = TS:Create(Mover, SlideInfo, {CFrame = Goal})
TramRunning = true; ToggleDoors(false)
Slide:Play(); Slide.Completed:Wait()
if Tram.Parent then
LastTrip = tick()
TramRunning = false
Direction = Direction * -1
ToggleDoors(true)
end
end
end
