Train Model Moving but I keep shaking while I standing Inside


As you can see I keep shaking while train moving
I want make game like Desert Bus

  • Does it Because Moving Train Script is Awful? or
  • PlatformStick Script Awful? or
  • Model it to lag?

If Moving Train: [Script]

local Train = workspace.Train
local Support = workspace.Support
local RunService = game:GetService("RunService")
--wait(2)

local speed = 70 -- Studs per second (5 units / 0.1 seconds = 50 studs/sec)

RunService.Heartbeat:Connect(function(deltaTime)
	local distanceToMove = speed * deltaTime

	Train:PivotTo(Train:GetPivot() * CFrame.new(0, 0, distanceToMove))
	Support:PivotTo(Support:GetPivot() * CFrame.new(0, 0, distanceToMove))
end)

Detail: This Script it make 2 model moving “Support” and “Train” moving same time

If PlatfromStick: [LocalScript]

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2


Function = RunService.Heartbeat:Connect(function()

	--------------------------------------------------------------- CHECK PLATFORM BELOW
	if not player.Character:FindFirstChild("HumanoidRootPart") then return end
	
	local RootPart = player.Character.HumanoidRootPart

	local Ignore = player.Character

	local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-50,0))

	local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray,Ignore)
	

	if Hit and Hit.Name == "NotFall" then -- Change "RaftTop" to whatever the moving part's name is

		--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

		local Train = Hit
		if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
			LastTrainCFrame = Train.CFrame -- This is updated later.
		end
		local TrainCF = Train.CFrame 

		local Rel = TrainCF * LastTrainCFrame:inverse()

		LastTrainCFrame = Train.CFrame -- Updated here.

		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
		--print("set")

	else
		LastTrainCFrame = nil -- Clear the value when the player gets off.

	end

	Function2 = player.Character.Humanoid.Died:Connect(function()
		Function:Disconnect() -- Stop memory leaks
		Function2:Disconnect() -- Stop memory leaks
	end)

end)

Detail: The White Platfrom make Player can stand still and jumping while train moving, but somehow i change name to floor as same name on floor train it not stick to player idk why this happen, does it effect to moving train script?

If Lag: How i can Reduce it?

Thank you so much yall!

1 Like

Humanoids was not really designed for it.
Instead you may try applying velocity

3 Likes

Velocity is a Thing make Part/Model Moving?!

Read them all before using any

AssemblyAngularVelocity

AssemblyLinearVelocity

1 Like

The “Humanoids” you said is on PlatfromStick?, I’m sorry am not a Scripter so what should i change

This platformStick may help.

-- Credits: Phoenixwhitefire 17/02/2022

local RunService = game:GetService("RunService")

local Character = script.Parent
local HumanoidRootPart = Character.HumanoidRootPart

local RayInfo = RaycastParams.new()
RayInfo.FilterType = Enum.RaycastFilterType.Blacklist
RayInfo.FilterDescendantsInstances = {Character}

local Down = Vector3.new(0, -100, 0)

local StandingOn
local LastCF

local function UpdateCF()
	local Hit = workspace:Raycast(HumanoidRootPart.Position, Down, RayInfo)
	
	if Hit then
		if not Hit.Instance:IsA("Terrain") then
			StandingOn = Hit.Instance
			LastCF = StandingOn.CFrame
		end
	else
		StandingOn = nil
		LastCF = nil
	end
end

RunService.Stepped:Connect(function()
	UpdateCF()
	
	RunService.Stepped:Wait()
	
	if StandingOn then
		local Relative = StandingOn.CFrame * LastCF:Inverse()
		
		HumanoidRootPart.CFrame = Relative * HumanoidRootPart.CFrame
	end
end)

Also it is better to make a train out of mechanical constraints, It had built in platformStick ( not for jump but you can still fix it using some custom script) like this.
or you can use Character Physics Controllers ( I am not recommend this because it kinds of complex to use )

1 Like

pretty sure most games with one vehicle that travels an infinite distance simply move the background/texture - and not the vehicle itself, if thats what you’re going for

4 Likes

Yea I want Inf Road like:
Subway Simulator
Desert Bus [Epic one]
van trip (alpha)
And After I test 20 minute i realize the Pixel when I go very far Studs, shaking my avatar

1 Like

Yeah, you might want to instead move the background. Same effect, but you’ll have to handle players outside (if you can exit). If they touch the ground - make it behave like a conveyor where they are left behind.

1 Like

That Work too but idk how Desert Bus Can make Realistic, Player jump out fall out and stand still while car moving away even even dont have conveyor

1 Like

I’m pretty sure the map moves as well, making the illusion.
I believe the way it works is - it generates sections of the map ahead, moves them back, and unloads them after a certain distance.
Either way, it doesn’t need to be super realistic to be fun or good.

If you move the train - you’ll begin experiencing floating point errors and the game will begin bugging out.

I’m no expert, so take this with a grain of salt - but I think that’s what’s being done.

2 Likes