Player clips into moving platforms and slides through them

I am working on a hard obby for my game that has moving platforms. The moving platforms are however causing problems because sometimes the player’s avatar will glitch/clip into the platform and slide through it into a obstacle.

Here’s a video of this glitch taking place:

Here is the Local Script for the moving platforms:

for i, child in pairs(game.Workspace.InsaneFolder:GetChildren()) do
	wait()
	if child.Name == "InsaneMove1" then
		local TweenService = game.TweenService
		local Info = TweenInfo.new(
			1.4,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			-1,
			true,
			0
		)


		local PropertyTable = {
			Position = child.Position + Vector3.new(0,15,0)
		}
		local Tween = TweenService:Create(child, Info, PropertyTable)
		Tween:Play()
	elseif child.Name == "InsaneMove2" then
		
		local TweenService = game.TweenService
		local Info = TweenInfo.new(
			1.1,
			Enum.EasingStyle.Linear,
			Enum.EasingDirection.Out,
			-1,
			true,
			0
		)


		local PropertyTable = {
			Position = child.Position + Vector3.new(0,15,0)
		}
		local Tween = TweenService:Create(child, Info, PropertyTable)
		Tween:Play()
		
		
	end
	
	end
6 Likes

The way to fix this is by using BodyMovers like AlignPosition which will more accurately calculate physics.

3 Likes

I don’t really have any experience using these and I feel like I would have to make a lot of changes for these to work. This problem isn’t really huge or game breaking are there any simpler solutions you could recommend?

1 Like

This might be happening because all of the platforms have an incorrect AssemblyLinearVelocity of 0, 0, 0 and because of that the character has a higher chance of clipping into the ground because the platform is moving up and the character on it isn’t moving up with it because the platform’s AssemblyLinearVelocity property is 0, 0, 0
To fix this you can create a table which stores the last position of every platform, initialize the position of every platform in the table to the platform’s current position, and on RunService.Stepped event you can first set the platform’s AssemblyLinearVelocity property to (CurrentPositionOfPlatform - LastPositionOfPlatform) / DeltaTime because Velocity = Distance / Time and then you can update the position of the platform inside of the table, here’s the code for that

local RunService = game:GetService("RunService")

local PlatformsInfo = {}

local function HandlePlatform(Platform)
	if Platform.Name == "InsaneMove1" or Platform.Name == "InsaneMove2" then
		table.insert(PlatformsInfo, {Platform = Platform, LastPosition = Platform.Position})
	end
end

for i, child in pairs(game.Workspace.InsaneFolder:GetChildren()) do
	HandlePlatform(child)
end

game.Workspace.InsaneFolder.ChildAdded:Connect(HandlePlatform)

RunService.Stepped:Connect(function(_, DeltaTime)
	for _, v in pairs(PlatformsInfo) do
		local Platform = v.Platform
		
		local LastPosition = v.LastPosition
		local NewPosition = Platform.Position
		
		Platform.AssemblyLinearVelocity = (NewPosition - LastPosition) / DeltaTime
		
		v.LastPosition = NewPosition
	end
end)
4 Likes

Does this run in the server? You could try doing the same in a local script, it would be smoother, maybe this was the problem

2 Likes