-
What do you want to achieve? I want to make a vehicle that can transport players and objects using roblox physics just like Dead Rails does.
-
What is the issue? I simply can’t make it. My vehicle is a model with a bunch of parts welded to a anchored primary part that i move using TweenService.
-
What solutions have you tried so far? I have looked at posts concerning this system, i have looked at Roblox Documentation for every instance concerning roblox physics. I have succeeded in some sort by combining AssemblyLinearVelocity and Tween but its very glitchy.
Here is my current script:
local tweenService = game:GetService("TweenService")
local van = script.Parent
local lever = van.Lever
local center = lever.Center
local primary = van.PrimaryPart
local switchOn = lever.On
local switchOff = lever.Off
local moveThread = nil
local moveTween = nil
local moveSpeed = 40
local targetPosition = primary.Position
for _, descendant in pairs(van:GetDescendants()) do
if descendant:IsA("BasePart") and descendant ~= primary then
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Part0 = descendant
weldConstraint.Part1 = primary
weldConstraint.Parent = descendant
end
end
local function switchVisibility(switch : BasePart, visible)
if visible then
switch.Transparency = 0
switch.CanCollide = true
switch.CanQuery = true
switch.CanTouch = true
else
switch.Transparency = 1
switch.CanCollide = false
switch.CanQuery = false
switch.CanTouch = false
end
end
switchOn.ClickDetector.MouseClick:Connect(function()
switchOn.ClickDetector.MaxActivationDistance = 0
switchVisibility(switchOn, false)
center.ToggleSound:Play()
moveThread = task.spawn(function()
while true do
primary.AssemblyLinearVelocity = primary.CFrame.LookVector * moveSpeed
moveTween = tweenService:Create(primary, TweenInfo.new(1, Enum.EasingStyle.Linear), {CFrame = primary.CFrame * CFrame.new(0, 0, -moveSpeed)})
moveTween:Play()
moveTween.Completed:Wait()
end
end)
primary["Car Engine"]:Play()
switchVisibility(switchOff, true)
switchOff.ClickDetector.MaxActivationDistance = 10
end)
switchOff.ClickDetector.MouseClick:Connect(function()
switchOff.ClickDetector.MaxActivationDistance = 0
switchVisibility(switchOff, false)
center.ToggleSound:Play()
if moveThread then
task.cancel(moveThread)
moveThread = nil
end
if moveTween then
moveTween:Pause()
moveTween = nil
end
primary["Car Engine"]:Stop()
primary.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
switchVisibility(switchOn, true)
switchOn.ClickDetector.MaxActivationDistance = 10
end)